forked from janbodnar/Python-Skolenie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecap.py
More file actions
105 lines (67 loc) · 1.82 KB
/
recap.py
File metadata and controls
105 lines (67 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python3
# recapitulation
# recap.py
import random
import os
# ******************************
# os module
print(os.getcwd())
try:
os.mkdir('newfolder')
except FileExistsError as e:
print(e)
print("******************************")
# ******************************
# list, for loop, built-ins
nums = [1, 2, 3, 4, 5]
print("There are {0} elements in the list".format(len(nums)))
for e in nums:
print(e, end=' ')
print()
print("maximum: {0}".format(max(nums)))
print("maximum: {0}".format(max(nums)))
print("summation: {0}".format(sum(nums)))
# ******************************
# while loop
male = False
male = bool(random.randint(0, 1))
if (male):
print("We will use name John")
else:
print("We will use name Victoria")
print("******************************")
# ******************************
# dictionary
weekend = { "Sun": "Sunday", "Mon": "Monday" }
vals = dict(one=1, two=2)
capitals = {}
capitals["svk"] = "Bratislava"
capitals["deu"] = "Berlin"
capitals["dnk"] = "Copenhagen"
d = { i: object() for i in range(4) }
print(weekend)
print(vals)
print(capitals)
print(d)
for k, v in weekend.items():
print("key: {0}, value: {1}".format(k, v))
print("******************************")
# ******************************
# while loop
i = len(nums) - 1
mysum = 0
while (i >= 0):
mysum += nums[i]
i -= 1
print("summation 2: {0}".format(mysum))
print("******************************")
# ******************************
# sets
set1 = { 'a', 'b', 'c', 'c', 'd' }
set2 = { 'a', 'b', 'x', 'y', 'z' }
print("Set 1:", set1)
print("Set 2:", set2)
print("intersection:", set1.intersection(set2))
print("union:", set1.union(set2))
print("difference:", set1.difference(set2))
print("symmetric difference:", set1.symmetric_difference(set2))