-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_flow_tools.py
More file actions
105 lines (76 loc) · 1.77 KB
/
Copy pathcontrol_flow_tools.py
File metadata and controls
105 lines (76 loc) · 1.77 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
x = int(input("Please enter an integer: "))
if x < 0:
x = 0
print("Negative changed to zero ")
elif x == 0:
print("Zero")
elif x == 1:
print("Single")
else:
print("More")
words = ["cat", "Windows", "defenestration"]
for w in words:
print(w, len(w))
users = {"Hans": "active", "Èlènore": "inactive", "Yun": "active"}
# iterate over a copy
for user, status in users.copy().items():
if status == "inactive":
del users[user]
active_users = {}
# create a new collection
for user, status in users.items():
if status == "active":
active_users[user] = status
for i in range(5):
print(i)
print(list(range(4,15)))
print(list(range(0, 10, 3)))
print(list(range(-10, -100, -30)))
a = ["Mary", "had", "a", "little", "lamb"]
for i in range(len(a)):
print(i, a[i])
for n in range(2, 10):
for i in range(2, n):
if n % x == 0:
print(n, "equals", x, "*", n/x)
# break or continue
break
else:
print(n, "is a prime number")
# the pass statement is used when a statement is required syntatically but the program requires no action. it's also used as a placeholder for a function.
"""
def http_error(status):
match status:
case 400:
return "Bad request"
case 404:
return "Not found"
case 418:
return "I am a teapot"
case _:
return "Something is wrong with the internet"
case 401 | 403 | 404:
return "Not Allowed"
# point is an x, y tuple
match point:
case (0, 0):
print("Origin")
case (0, y):
print(f"Y = {y}")
case _:
raise ValueError("Not a point")
class Point:
x: int
y: int
def where_is(point):
match point:
case Point (x = 0, y = 0):
print(Origin)
case Point ( x = 0, y = y):
print(f"Y = {y}")
#...
case Point ():
print("somewhere else")
case _:
print("Not a point")
"""