This repository was archived by the owner on Oct 20, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy path05_02.BonusExamples.py
More file actions
153 lines (118 loc) · 4.81 KB
/
Copy path05_02.BonusExamples.py
File metadata and controls
153 lines (118 loc) · 4.81 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
todos = []
while True:
user_decision = input("Type either Add, Show, Edit, Complete or Exit:")
user_decision = user_decision.strip().casefold()
match user_decision:
case "add":
todo = input("Enter a To-Do Item:")
todos.append(todo)
case "show" | "display":
print()
for index, item in enumerate(todos):
item = item.title()
row = f"{index+1}: {item}"
print(row)
print(f"\nYour To-Do List is {len(todos)} items long.")
print()
case "edit":
number = int(input("Please enter the number of the To-Do Item you wish to edit."))
number = number-1
# Two ways of printing a variable in a line of code. Here's way #1, old schoolway.
print("You selected {}.".format(todos[number]))
new_todo = input("Please enter the To-Do Item you wish to replace this item.")
todos[number] = new_todo
# Here's the easier way to do it, as an "f-string literal" as autorecommended by PyCharm.
print(f"Your new To-Do Item is {todos[number]}.")
case "complete":
# dir(list)
# help(list.remove)
# Go to the end of this line of code to see more messing around
number = int(input("Please enter the number of the To-Do Item you wish to mark as completed."))
todos.pop(number - 1)
case "exit":
break
case _:
print("You entered an unknown command.\n"
"Please type either Add, Show or Exit:")
print("Good bye!")
# Numbers to words
# In the terminal, I typed pip install num2words, then:
from num2words import num2words
todos = []
while True:
user_decision = input("Type either Add, Show, Edit, Complete or Exit:")
user_decision = user_decision.strip().casefold()
match user_decision:
case "add":
todo = input("Enter a To-Do Item:")
todos.append(todo)
case "show" | "display":
print()
for index, item in enumerate(todos):
item = item.title()
row = f"{index+1}: {item}"
print(row)
print(f"\nYour To-Do List is {num2words(len(todos))} items long.")
print()
case "edit":
number = int(input("Please enter the number of the To-Do Item you wish to edit."))
number = number-1
# Two ways of printing a variable in a line of code. Here's way #1, old schoolway.
print("You selected {}.".format(todos[number]))
new_todo = input("Please enter the To-Do Item you wish to replace this item.")
todos[number] = new_todo
# Here's the easier way to do it, as an "f-string literal" as autorecommended by PyCharm.
print(f"Your new To-Do Item is {todos[number]}.")
case "complete":
# dir(list)
# help(list.remove)
# Go to the end of this line of code to see more messing around
number = int(input("Please enter the number of the To-Do Item you wish to mark as completed."))
todos.pop(number - 1)
case "exit":
break
case _:
print("You entered an unknown command.\n"
"Please type either Add, Show or Exit:")
print("Good bye!")
# Here's a weird trick:
for i, j in enumerate("Hello world."):
print(i,j)
for i in enumerate("Hello world."):
print(i)
# See day 5 in notes for an explanation of why these outputs look particularly different.
# New little program
waiting_list = ["Sean","Ben","CINDY!!!!!!"]
for index, item in enumerate(waiting_list):
row = f"{index + 1}. {item.capitalize()}."
print(row)
# Now lets sort
help(list.sort)
waiting_list = ["Sean","Ben","CINDY!!!!!!"]
waiting_list.sort()
for index, item in enumerate(waiting_list):
row = f"{index + 1}. {item.capitalize()}."
print(row)
waiting_list
# Note that waiting_list was permanently altered. Good or bad, that depends.
waiting_list = ["Sean","Ben","CINDY!!!!!!"]
waiting_list.sort(reverse=True)
for index, item in enumerate(waiting_list):
row = f"{index + 1}. {item.capitalize()}."
print(row)
waiting_list
# QUIZ
for i, j in enumerate("abcd"):
print(i + 1)
for i, j in enumerate("abcd"):
print(i.capitalize())
# Coding exercises here: https://www.udemy.com/course/the-python-mega-course/learn/lecture/32165920#overview
# BUG SOLVING:https://www.udemy.com/course/the-python-mega-course/learn/lecture/32166178#overview
menu = ["pasta", "pizza", "salad"]
user_choice = int(input("Enter the index of the item: "))
message = f"You chose {menu[user_choice]}."
print(message)
# BUG #2
menu = ["pasta", "pizza", "salad"]
for i, j in enumerate(menu):
print(F"{i}.{j}")