Python编程从入门到实践第七章

第七章

#7.1动手试一试
message_1 = input("Let me see if I could find you a ")
print(message_1)
name = input("Please input your name: ")
print(name)
print(f"hello,{name.title()}")
age = input("Please input your age: \n")#可以把输入的名称转到下一行
print(age)
#print(age)
#print(age > 7)
number_age = int(age)
print(number_age > 7) 
number_guest = input("hello,how many people is going: ")
int_guest = int(number_guest)
if int_guest > 8:
	print("sorry")
else:
	print("ok")
current_number = 1
while current_number <= 5:
	print(current_number)
	current_number += 1
prompt = "\nTell me something:"
prompt += "\nrepeat: "
message_2 = " "
while message_2 != "quit":
	message_2 = input(prompt)
	print(message_2)
prompt_2 = "\nTell me something your name: "
prompt_2 += "\nrepeat: "
active = True #使用标志
while active:
	real_name = input(prompt_2)
	if real_name == "quit":
		active = False
	else:
		print(real_name)
#下面使用break
prompt_3 = "\nTell me something her name: "
prompt_3 += "\nrepeat: "
while True:
	real_name = input(prompt_3)
	if real_name == "quit":
		break
	else:
		print(real_name)
stra_num = 10
while stra_num < 19:
	stra_num += stra_num
	if stra_num % 2 == 0:
		continue #使用continue忽略剩下的代码并返回循环的开头
	print(stra_num)
active = True
while active:
	peiliao = input("请输入你想要的配料: \n")
	if peiliao != 'quit':
		print(f"我们添加了{peiliao}作为配料!")
	else:
		active = False
while True:
	age = input("请输入你的年龄: ")
	if age == 'quit':
		break
	else:
		real_age = int(age)
		if real_age < 3:
			print("你需要支付5美元")
		elif  3<= real_age and real_age <=12:
			print("你需要支付10美元")
		else:
			print("你需要支付15美元")
unconfirmed_users = ['alice','tom','jim','lucy']
confirmed_users = []
while unconfirmed_users:
	unconfirmed_num = len(unconfirmed_users)
	confirmed_user = unconfirmed_users.pop()
	confirmed_users.append(confirmed_user)
	print(f"{confirmed_user},he or she has been confirmed.")
for confirmed_user in confirmed_users:
	print(f"we have {len(confirmed_users)} in confirmed group!")
responses = {}
active = True
while active:
	name = input("what is your name : ")
	mountain = input("which mountain will you climb? ")
	decide = input("if other people can answer? yes/no ")
	responses[name] = [mountain]
	if decide == 'no':
		active = False
for name,mountain in responses.items():
	print(f"{name} is going to climb {mountain}!")
food_orders = ['baozi','mantou','jiaozi','kongzi','kongzi','kongzi','kongzi']
finshed_food = []
print("kongzi is out")
for food in food_orders:
	if food == 'kongzi':
		food_orders.remove('kongzi')
		print(food_orders)
while food_orders:
	#for order in food_orders:
	food = food_orders.pop()
	print(f"I am making your {food}")
	finshed_food.append(food)
for food in finshed_food:
	print(f"we have finished!{food}")
print(finshed_food)


输出结果
Let me see if I could find you a jj
jj
Please input your name: jj
jj
hello,Jj
Please input your age:
23
23
True
hello,how many people is going: 9
sorry
1
2
3
4
5

Tell me something:
repeat: qqq
qqq

Tell me something:
repeat: quiy
quiy

Tell me something:
repeat: quit
quit

Tell me something your name:
repeat: jj
jj

Tell me something your name:
repeat: quit

Tell me something her name:
repeat: junjun
junjun

Tell me something her name:
repeat: quit
请输入你想要的配料:
dabin
我们添加了dabin作为配料!
请输入你想要的配料:
quit
请输入你的年龄: 23
你需要支付15美元
请输入你的年龄: quit
Traceback (most recent call last):
File “第七章.py”, line 78, in
print(f"{unconfirmed_user},he or she has been confirmed.")
NameError: name ‘unconfirmed_user’ is not defined

C:\Users\PC\Desktop\python_work>python 第七章.py
Let me see if I could find you a kkk
kkk
Please input your name: kk
kk
hello,Kk
Please input your age:
12
12
True
hello,how many people is going: 9
sorry
1
2
3
4
5

Tell me something:
repeat: quit
quit

Tell me something your name:
repeat: quit

Tell me something her name:
repeat: quit
请输入你想要的配料:
quit
请输入你的年龄: 23
你需要支付15美元
请输入你的年龄: quit
lucy,he or she has been confirmed.
jim,he or she has been confirmed.
tom,he or she has been confirmed.
alice,he or she has been confirmed.
we have 4 in confirmed group!
we have 4 in confirmed group!
we have 4 in confirmed group!
we have 4 in confirmed group!
what is your name : liu
which mountain will you climb? liuyifei
if other people can answer? yes/no no
liu is going to climb [‘liuyifei’]!
kongzi is out
[‘baozi’, ‘mantou’, ‘jiaozi’, ‘kongzi,kongzi’, ‘kongzi’]
[‘baozi’, ‘mantou’, ‘jiaozi’, ‘kongzi,kongzi’]
I am making your kongzi,kongzi
I am making your jiaozi
I am making your mantou
I am making your baozi
we have finished!kongzi,kongzi
we have finished!jiaozi
we have finished!mantou
we have finished!baozi
[‘kongzi,kongzi’, ‘jiaozi’, ‘mantou’, ‘baozi’]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值