python第七章习题

这篇博客展示了Python编程中关于交互式输入和条件判断的练习,包括根据年龄决定是否需要支付费用,以及收集多人旅行目的地的偏好。用户可以输入'quit'退出程序。最后,程序会列出每个人想去的地方。
摘要由CSDN通过智能技术生成

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)<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值