Python作业(7.1-7.10)

Python第七章作业

7-1 汽车租赁 : 编写一个程序, 询问用户要租赁什么样的汽车, 并打印一条消息, 如“Let me see if I can find you a Subaru”

car=input("What kind of car would you like to rent?")
print("Let me see if I can find you a "+car+".")


7-2 餐馆订位 : 编写一个程序, 询问用户有多少人用餐。 如果超过8人, 就打印一条消息, 指出没有空桌; 否则指出有空桌。

number=input("How many people have ordered a meal?")
number=int(number)
if number > 8:
	print("Sorry,there is no  available table")
else:
	print("OK,welcome!There is a table for you")

7-4 比萨配料 : 编写一个循环, 提示用户输入一系列的比萨配料, 并在用户输入 'quit' 时结束循环。 每当用户输入一种配料后, 都打印一条消息, 说我们会在比萨中添加这种配料

message='Please input ingredients which you would like to add in your Pizza'
message+="\nAnd you can input 'quit' to end inputing"
print(message)
while message!='quit':
	message=input()
	print("Ok,we will add "+message+" in your Pizza.")
print("End adding")

7-6 三个出口 : 以另一种方式完成练习 7-4 或练习 7-5 , 在程序中采取如下所有做法。
while 循环中使用条件测试来结束循环。
使用变量
active 来控制循环结束的时机。
使用
break 语句在用户输入 'quit' 时退出循环。

message='Please input ingredients which you would like to add in your Pizza'
message+="\nAnd you can input 'quit' to end inputing"
print(message)
acctive=True
while acctive:
	message=input()
	if message=='quit':
		break
		acctive=False
	else:
		print("Ok,we will add "+message+" in your Pizza.")
print("End adding")


7-7 无限循环 : 编写一个没完没了的循环, 并运行它(要结束该循环, 可按Ctrl +C, 也可关闭显示输出的窗口) 。

true=True
while true:
	print("Never stop")


7-8 熟食店 : 创建一个名为sandwich_orders 的列表, 在其中包含各种三明治的名字; 再创建一个名为finished_sandwiches 的空列表。 遍历列表sandwich_orders , 对于其中的每种三明治, 都打印一条消息, 如I made your tuna sandwich , 并将其移到列表finished_sandwiches 。 所有三明治都制作好后, 打印一条消息, 将这些三明治列出来。

finished_sandwiches=[]
sandwich_orders=['Chicken sandwich','Beef sandwich','Avovado sanfwich']
while sandwich_orders:
	current=sandwich_orders.pop()
	finished_sandwiches.append(current)
for sandwich in finished_sandwiches:
	print(sandwich)




猜你喜欢

转载自blog.csdn.net/qq_36755175/article/details/79702497
7.1