7-1
car=input('What kind of car do you want to rent?')
print('Let me see if I can find you a '+car+' .')
What kind of car do you want to rent?Subaru
Let me see if I can find you a Subaru .
7-2
i=input('How many people are there in your party?')
if int(i) >= 8:
print('I am sorry we do not have a vacant table.')
else:
print('Ok,we have some vacant tables.')
How many people are there in your party?10
I am sorry we do not have a vacant table.
How many people are there in your party?3
Ok,we have some vacant tables.
7-3
i=input('请输入一个数字:')
if int(i)%10 :
print('这个数不是10的整数倍。')
else:
print('这个数是10的整数倍。')
请输入一个数字:11
这个数不是10的整数倍。
请输入一个数字:50
这个数是10的整数倍。
7-4
while True:
food_ingredient=input('请输入一种披萨配料:')
if food_ingredient != 'quit':
print('我们会在披萨中加入'+food_ingredient+'。')
else:
break
请输入一种披萨配料:salt
我们会在披萨中加入salt。
请输入一种披萨配料:sugar
我们会在披萨中加入sugar。
请输入一种披萨配料:quit
7-5
while True:
age=input('请输入您的年龄:')
if age != 'quit':
if int(age) < 3:
print('免费!')
elif int(age) >= 3 and int(age) < 12:
print('票价为10美元')
else:
print('票价为15美元')
else:
break
请输入您的年龄:50
票价为15美元
请输入您的年龄:2
免费!
请输入您的年龄:10
票价为10美元
请输入您的年龄:quit
7-6
active=True
while active:
age=input('请输入您的年龄:')
if age != 'quit':
if int(age) < 3:
print('免费!')
elif int(age) >= 3 and int(age) < 12:
print('票价为10美元')
else:
print('票价为15美元')
else:
active=False
请输入您的年龄:10
票价为10美元
请输入您的年龄:quit
7-7
i=1
while 1:
print(i)
7-8
sandwich_orders=['A_sandwich','B_sandwich','C_sandwich']
finished_sandwich=[]
while sandwich_orders:
sandwich=sandwich_orders.pop()
finished_sandwich.append(sandwich)
print('I made your '+sandwich+' !')
print('All sandwiches have been made.')
for sandwich in finished_sandwich:
print(sandwich)
I made your C_sandwich !
I made your B_sandwich !
I made your A_sandwich !
All sandwiches have been made.
C_sandwich
B_sandwich
A_sandwich
7-9
print('All the pastrami is sold out.')
sandwich_orders=['pastrami','A_sandwich','pastrami','B_sandwich','pastrami','C_sandwich']
finished_sandwich=[]
while sandwich_orders:
sandwich=sandwich_orders.pop()
if sandwich != 'pastrami':
finished_sandwich.append(sandwich)
print('I made your '+sandwich+' !')
else:
continue
print('All sandwiches have been made.')
for sandwich in finished_sandwich:
print(sandwich)
All the pastrami is sold out.
I made your C_sandwich !
I made your B_sandwich !
I made your A_sandwich !
All sandwiches have been made.
C_sandwich
B_sandwich
A_sandwich
7-10
while True:
scenic_spots = input('If you could visit one place in the world,where would you go?')
if scenic_spots != 'quit':
print('I want to go to '+scenic_spots+'.')
else:
break