作业
7-1 汽车租赁
- 询问用户要什么样的汽车,并打印信息
代码
car=input("What kind of cars do you want to rent?\n")
print("Let me see if I can find you a " + car)
输出
What kind of cars do you want to rent?
QQ
Let me see if I can find you a QQ
7-2 餐馆订位
- 询问有多少人用餐,若多于8个,则指出没有座位,否则指出有空桌
代码
num=int(input("How many people are dining?\n"))
if num > 8:
print("None empty tables now!")
else:
print("There are empty tables here.")
输出
How many people are dining?
12
None empty tables now!
7-3 10的整数倍
- 用户输入一个数,判断该数是否为数的整数被整除
代码
num=(input("Please input a numer: "))
if int(num)%10 == 0:
print (str(num)+" is a multiple of 10")
else:
print (str(num)+" is not a multiple of 10")
输出
Please input a numer: 6
6 is not a multiple of 10
7-8 熟食店
- 创建名为sandwich_orders的列表,遍历列表并输出
代码
sandwich_orders=['apple sandwich', 'banana sandwich', 'strawberry sandwich']
finish_sandwiches = []
while sandwich_orders:
finish_sandwiches.append(sandwich_orders.pop(0))
print ("I made your " + finish_sandwiches[-1])
输出
I made your apple sandwich
I made your banana sandwich
I made your strawberry sandwich