#7-1
car = input("What brand of car do you want? -")
print("Let me see if I can find you a " + car + '\n')
#7-3
num = input("Please input a number: ")
if int(num) % 10 == 0:
print("It's is an integral multiple of 10\n")
else:
print("It's not an integral multiple of 10\n")
#7-5
while True:
age = input("What is your age please? (enter 'exit' to quit) \n")
if age == 'exit':
break
age_num = int(age)
price = 0
if age_num < 3:
price = 0
elif age_num <= 12:
price = 10
else:
price = 15
if price == 0:
print("It free, baby!")
else:
print("It " + str(price) + " dolars, my friend")
print('\n')
#7-8
sandwich_orders = ['good', 'black', 'white', 'tuna', 'black']
finished_sandwiches = []
while len(sandwich_orders) > 0:
sandwich = sandwich_orders.pop()
print("I made your " + sandwich + " sandwich")
finished_sandwiches.append(sandwich)
print("All the sandwiches I made are: ")
for sandwich in finished_sandwiches:
print("\t" + sandwich)
print('\n')
#7-9
sandwich_orders = ['good', 'pastrami', 'white', 'pastrami', 'tuna', 'pastrami', 'black']
print(sandwich_orders)
finished_sandwiches = []
print("There is no pastrami")
while "pastrami" in sandwich_orders:
sandwich_orders.remove("pastrami")
while len(sandwich_orders) > 0:
sandwich = sandwich_orders.pop()
print("I made your " + sandwich + " sandwich")
finished_sandwiches.append(sandwich)
print("All the sandwiches I made are: ")
for sandwich in finished_sandwiches:
print("\t" + sandwich)
输入:
BMW
2
6
99
3
2
exit
输出:
What brand of car do you want? -BMW
Let me see if I can find you a BMW
Please input a number: 2
It's not an integral multiple of 10
What is your age please? (enter 'exit' to quit)
6
It 10 dolars, my friend
What is your age please? (enter 'exit' to quit)
99
It 15 dolars, my friend
What is your age please? (enter 'exit' to quit)
3
It 10 dolars, my friend
What is your age please? (enter 'exit' to quit)
2
It free, baby!
What is your age please? (enter 'exit' to quit)
exit
I made your black sandwich
I made your tuna sandwich
I made your white sandwich
I made your black sandwich
I made your good sandwich
All the sandwiches I made are:
black
tuna
white
black
good
['good', 'pastrami', 'white', 'pastrami', 'tuna',
'pastrami', 'black']
There is no pastrami
I made your black sandwich
I made your tuna sandwich
I made your white sandwich
I made your good sandwich
All the sandwiches I made are:
black
tuna
white
good