#7.1
car = input("你要一輛什么樣的汽車充坑?")
print("讓我為您找一輛" + car)
輸出:
你要一輛什么樣的汽車党窜?奔馳
讓我為您找一輛奔馳
#7.2
try:
num = int(input("請問你們有多少人用餐?"))
except ValueError as err:
pass
if num > 8:
print("不好意思,沒有空桌了")
else:
print("有空桌")
輸出:
請問你們有多少人用餐薯定?10
不好意思,沒有空桌了
#7.3
num = int(input("請輸入一個數(shù)字:"))
if num % 10 == 0:
print(str(num) + "是10的整數(shù)倍")
else:
print(str(num) + "不是10的整數(shù)倍")
輸出:
請輸入一個數(shù)字:30
30是10的整數(shù)倍
#7.4
prompt = ("請輸入你要給饃里加的配料:")
prompt += "\n輸入 'quit' 退出程序。"
ingredient = ""
while ingredient != 'quit':
ingredient = input(prompt)
if ingredient != 'quit':
print(ingredient)
輸出:
請輸入你要給饃里加的配料:
輸入 'quit' 退出程序。洋芋絲
洋芋絲
請輸入你要給饃里加的配料:
輸入 'quit' 退出程序线衫。洋柿子
洋柿子
請輸入你要給饃里加的配料:
輸入 'quit' 退出程序。quit
#7.5
prompt = "請輸入你的年齡:"
prompt += "\n(輸入'quit'退出程序惑折。)"
age = 0
while age != 'quit':
age = input(prompt)
if age != 'quit':
if int(age) < 3:
print("免費")
elif int(age) >3 and int(age) <= 12:
print("10美元")
else:
print("15美元")
輸出:
請輸入你的年齡:
(輸入'quit'退出程序授账。)1
免費
請輸入你的年齡:
(輸入'quit'退出程序。)4
10美元
請輸入你的年齡:
(輸入'quit'退出程序惨驶。)19
15美元
請輸入你的年齡:
(輸入'quit'退出程序白热。)quit
#7.6
prompt = "請輸入你要給饃里加的配料:"
prompt += "\n(輸入 'quit' 退出程序。)"
ingredient = ""
active = True
while active:
ingredient = input(prompt)
if ingredient == "quit":
active = False
break
else:
print(ingredient)
輸出:
請輸入你要給饃里加的配料:
(輸入 'quit' 退出程序粗卜。)土豆絲
土豆絲
請輸入你要給饃里加的配料:
(輸入 'quit' 退出程序屋确。)洋芋絲
洋芋絲
請輸入你要給饃里加的配料:
(輸入 'quit' 退出程序。)quit
prompt = "請輸入你的年齡:"
prompt += "\n(輸入'quit'退出程序续扔。)"
age = 0
active = True
while active:
age = input(prompt)
if age == 'quit':
active = False
break
else:
if int(age) < 3:
print("免費")
elif int(age) >3 and int(age) <= 12:
print("10美元")
else:
print("15美元")
輸出:
請輸入你的年齡:
(輸入'quit'退出程序攻臀。)13
15美元
請輸入你的年齡:
(輸入'quit'退出程序。)quit
#7.7
i = 0
while True:
i += 1
print(i)
#7.8
jiamos = ["肉夾饃","土豆絲夾饃","洋芋絲夾饃"]
finished_jiamos = []
while jiamos:
for jiamo in jiamos:
print("我給你做了個" + jiamo)
jiamos.remove(jiamo)
finished_jiamos.append(jiamo)
print(finished_jiamos)
輸出:
我給你做了個肉夾饃
我給你做了個洋芋絲夾饃
我給你做了個土豆絲夾饃
['肉夾饃', '洋芋絲夾饃', '土豆絲夾饃']
#7.9
jiamo_orders = ["肉夾饃","土豆絲夾饃","肉夾饃","肉夾饃","洋芋絲夾饃"]
print("肉夾饃賣完了")
finished_jiamos = []
for jiamo in jiamo_orders:
jiamo_orders.remove("肉夾饃")
active = True
while active:
for jiamo in jiamo_orders:
print("我給你做了個" + jiamo)
finished_jiamos.append(jiamo)
if jiamo_orders == finished_jiamos:
active = False
print(finished_jiamos)
輸出:
肉夾饃賣完了
我給你做了個土豆絲夾饃
我給你做了個洋芋絲夾饃
['土豆絲夾饃', '洋芋絲夾饃']
#7.10
prompt = "如果你可以去地球上的的一個城市旅行纱昧,你會去哪個城市刨啸?"
prompt += "\n(輸入quit退出程序。)"
while True:
city = input(prompt)
if city == "quit":
break
else:
print("我要去" + city)
輸出:
如果你可以去地球上的的一個城市旅行识脆,你會去哪個城市设联?
(輸入quit退出程序善已。)東京
我要去東京
如果你可以去地球上的的一個城市旅行,你會去哪個城市离例?
(輸入quit退出程序换团。)quit