-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchpt7practice.py
More file actions
137 lines (123 loc) · 3.8 KB
/
chpt7practice.py
File metadata and controls
137 lines (123 loc) · 3.8 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
#Chapter 7 practice
# Linhe Sun
# practice 7-1
car = input("Tell me what type of cars you want?\n")
print("Let me see if I can find you a(n) " + car.title() + ".")
# practice 7-2
number = input("Hello, could you tell me how many people will come for dinner?")
if int(number) > 8:
print("Sorry, there are no empty tables now.")
else:
print("Welcome, the waitress will show you the way.")
# practice 7-3
number = input("Type a number to test if it can be exact divided by 10:\n")
if int(number) % 10 == 0:
print("Yes")
else:
print("No")
# practice 7-4
prompt = "Please tell us what you want to add in your pizza:"
prompt += "\n(Type quit to quit)\n"
message = ""
while message.lower() != "quit":
message = input(prompt)
if message.lower() != "quit":
print("OK, we will add " + message + " in your pizza!")
# practice 7-5
age = input("Please tell us your age:\n")
if int(age) < 3:
print("You can watch the film free.")
elif int(age) < 12:
print("You should pay $10.")
else:
print("You should pay $15.")
# practice 7-6
prompt = "Please tell us your age:\n"
age = ""
while age == "":
age = input(prompt)
if int(age) < 3:
print("You can watch the film free.")
elif int(age) < 12:
print("You should pay $10.")
else:
print("You should pay $15.")
prompt = "Please tell us your age:\n"
age = ""
active = True
while active == True:
age = input(prompt)
if int(age) < 3:
print("You can watch the film free.")
elif int(age) < 12:
print("You should pay $10.")
else:
print("You should pay $15.")
active = False
prompt = "Please tell us your age:"
prompt += "\n(Type quit to quit)\n"
age = ""
active = True
while active == True:
age = input(prompt)
if age.lower() == "quit":
break
elif int(age) < 3:
print("You can watch the film free.")
elif int(age) < 12:
print("You should pay $10.")
else:
print("You should pay $15.")
# practice 7-7
prompt = "Please tell us your age:"
prompt += "\n(This is a infinite loop)\n"
age = ""
active = True
while active == True:
age = input(prompt)
if age.isdigit():
if int(age) < 3:
print("You can watch the film free.")
elif int(age) < 12:
print("You should pay $10.")
else:
print("You should pay $15.")
else:
print("You should type a number!")
# practice 7-8
sandwich_orders = ['tuna', 'vegetable', 'chicken']
finished_sandwiches = []
while sandwich_orders:
sandwich = sandwich_orders.pop()
print("I made your " + sandwich + " sandwich.")
finished_sandwiches.append(sandwich)
print("These sandwiches are made:")
for sandwich in finished_sandwiches:
print(sandwich.title() + " Sandwich.")
# practice7-9
sandwich_orders = ['tuna', 'vegetable', 'chicken']
sandwich_orders += ['pastrami', 'apple', 'pastrami', 'chicken', 'pastrami']
print(sandwich_orders)
while 'pastrami' in sandwich_orders:
sandwich_orders.remove('pastrami')
print(sandwich_orders)
#practice 7-10
places = {}
active = True
while active == True:
name = input("Please tell us your name:\n")
place = input("If you could visit one place in the world, where would you go?\n")
places[name] = place
repeat = 'yes'
while repeat:
repeat = input("Would you like to let another person respond?(yes/no)\n")
if repeat.lower() == 'yes':
print("Thanks.")
break
elif repeat.lower() == 'no':
active = False
break
else:
print("Please type yes or no.\n")
for name, place in places.items():
print(name.title() + " want to visit " + place.title() + " the most in the world.")