python第七章习题

7-3

number = input()
if int(number) % 10 == 0:
	print("yes")
else:
	print("no")

输出结果:

10

yes

15

no

7-5

while True:
	age = input("How old are you?(input quit to quit)\n")
	if age == "quit":
		exit()
	elif int(age) < 3:
		print("you are free.")
	elif int(age) >= 3 and int(age) <= 12:
		print("you have to pay 10 dollars.")
	else:
		print("you have to pay 15 dollars.")

输出结果:

How old are you?(input quit to quit)
2
you are free.
How old are you?(input quit to quit)
10
you have to pay 10 dollars.
How old are you?(input quit to quit)
15
you have to pay 15 dollars.
How old are you?(input quit to quit)
12
you have to pay 10 dollars.
How old are you?(input quit to quit)
quit

7-6.1

age = input("How old are you?(input quit to quit)\n")
while age != "quit":
	if int(age) < 3:
		print("you are free.")
	elif int(age) >= 3 and int(age) <= 12:
		print("you have to pay 10 dollars.")
	else:
		print("you have to pay 15 dollars.")
	age = input("How old are you?(input quit to quit)\n")

7-6.2

active = True
while active:
	age = input("How old are you?(input quit to quit)\n")
	if age == "quit":
		active = False
	elif int(age) < 3:
		print("you are free.")
	elif int(age) >= 3 and int(age) <= 12:
		print("you have to pay 10 dollars.")
	else:
		print("you have to pay 15 dollars.")

7-6.3

active = True
while active:
	age = input("How old are you?(input quit to quit)\n")
	if age == "quit":
		break
	elif int(age) < 3:
		print("you are free.")
	elif int(age) >= 3 and int(age) <= 12:
		print("you have to pay 10 dollars.")
	else:
		print("you have to pay 15 dollars.")

输出结果:同7-5

7-10

name = ""
place = ""
active = True

places = {}

while active:
	name = input("What is your name? ")
	place = input("If you could visit one place in the world,where would you go? ")
	flag = input("Would you like to let another person respond(yes or no)? ")
	while True:
		if flag == "no":
			active = False
			break
		elif flag != "yes":
			flag = input("Please enter yes or no? ")
		else:
			break
	places[name] = place

for key,value in places.items():
	print(key + " would like to go to " + value + ".")

输出结果:

What is your name? Eric
If you could visit one place in the world,where would you go? London
Would you like to let another person respond(yes or no)? yes
What is your name? Kangkang
If you could visit one place in the world,where would you go? Sichuan
Would you like to let another person respond(yes or no)? yes
What is your name? Luffy
If you could visit one place in the world,where would you go? Tokyo
Would you like to let another person respond(yes or no)? no
Luffy would like to go to Tokyo.
Kangkang would like to go to Sichuan.
Eric would like to go to London.


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值