This repository was archived by the owner on Oct 20, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy path03_03_CodeExperiments.py
More file actions
86 lines (70 loc) · 2.12 KB
/
Copy path03_03_CodeExperiments.py
File metadata and controls
86 lines (70 loc) · 2.12 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
# code from yesterday
todos = []
while True:
user_decision = input("Type either Add, Show or Exit:")
user_decision = user_decision.strip()
match user_decision.casefold():
case "add":
todo = input("Enter a To-Do Item:")
todos.append(todo)
case "show":
for item in todos:
print(item)
case "exit":
break
print("Good bye!")
# code from now
todos = []
while True:
user_decision = input("Type either Add, Show or Exit:")
user_decision = user_decision.strip()
match user_decision.casefold():
case "add":
todo = input("Enter a To-Do Item:")
todos.append(todo)
case "show":
for item in todos:
print(item)
case "exit":
break
case _:
print("You entered an unknown command.\n"
"Please type either Add, Show or Exit:")
print("Good bye!")
# OR, using IF and ELSE:
todos = []
while True:
user_decision = input("Type either Add, Show or Exit:")
user_decision = user_decision.strip().casefold()
if user_decision == "add":
todo = input("Enter a To-Do Item:")
todos.append(todo)
elif user_decision == "show":
for item in todos:
print(item)
elif user_decision == "exit":
break
else:
print("You entered an unknown command.\n"
"Please type either Add, Show or Exit:")
print("Good bye!")
# This method above is way more annoying to type though, so no thanks.
# Back to the video
todos = []
while True:
user_decision = input("Type either Add, Show or Exit:")
user_decision = user_decision.strip()
match user_decision.casefold():
case "add":
todo = input("Enter a To-Do Item:")
todos.append(todo)
case "show" | "display":
for item in todos:
item = item.title()
print(item)
case "exit":
break
case _:
print("You entered an unknown command.\n"
"Please type either Add, Show or Exit:")
print("Good bye!")