7-1 汽车租赁
type=input("What kind of car do you want:")
print('\nLet me see if I can find you a ' + type)
7-2 餐馆订位
number = int(input('How many people have dinner :'))
if number > 8:
print('\nsorry,There is no table in free')
else:
print('OK,I am waiting for you')
number=int(input())
7-3 10的整数倍
num=int(input('输入数字:'))
if num%10==0:
print(str(num) + "是10的倍数")
else:
print(str(num)+"不是10的倍数")
7-4 方法一 比萨配料
prompt="请输入配料"
prompt+='\n想加入的配料:'
while True:
message=input(prompt)
if message=="quit":
break
else:
print("\n添加"+message)
方法二 比萨配料
print("请输入配料,quit退出")
ingredients=""
while ingredients != "quit":
ingredients = input ("想在pizza中加啥:")
if ingredients != "quit":
print("加入"+ ingredients)
7-5 方法一 电影票
years = '\nPlease input your years old:'
years += "\n(Enter 0 when you are finished)"
while True:
old = int(input(years))
if old == "0":
break
elif old < 3:
cost = 'free'
elif old < 12:
cost = 10
else:
cost = 15
print('\nThe price of your ticket is ' + str(cost))
# 方法二电影票
print("请输入年龄,计算票价,*退出")
age=""
while age !="*":
age=input("你多大:")
if age != "*":
age=int(age)
if age <0:
print("请重新输入")
elif age>=0 and age<3:
price=0
elif age>=3 and age<18:
price=10
elif age >18:
price=15
print('You admission cost is '+ price.__str__()+'$.')
print('请输入年龄,计算票价,*退出')
7-6 三个出口
age = ''
while True:
age = input("您好,请问您的年龄是多少:")
if age == 'qiut':
print("qiut")
break
elif int(age) < 0:
print("你不是人,请回你的火星去。")
elif int(age) < 3:
print("您好,您免费哦!")
elif int(age) <= 12:
print("您好,收费金额为:10元")
elif int(age) > 12:
print("您好,收费金额为:15元")
7-7无线循环
a=1
while True:
print(a)
a=2
a+=1
# 7-8 熟食店
sandwich_orders =["A","B","C"]
finished_sandwiches =[]
while sandwich_orders:
介质=sandwich_orders.pop()
finished_sandwiches.append(介质)
# print('finished_sandwiches')
for sandwich in finished_sandwiches:
print(sandwich)
#7-9 五香烟熏牛肉
sandwich_orders =["A","五香牛肉","C","五香牛肉","B","五香牛肉"]
while "五香牛肉" in sandwich_orders:
sandwich_orders.remove('五香牛肉')
for sandwich in sandwich_orders:
print(sandwich)
#7-10 梦想的度假胜地
namesCitys = {}
verdict = True
while verdict:
name = input("您好,您叫什么名字?(输入'qiut即结束')")
if name == 'qiut':
break
citys = input("如果你能去到世界上的一个地方,你会去哪里(输入'qiut即结束')")
if citys == 'qiut':
break
namesCitys[name] = citys
print(namesCitys)