Python编程:条件语句与循环结构深度解析
知识测试与实践
在编程学习中,知识测试是巩固所学内容的有效方式。这次,我们将进行一个小测试,它会综合你目前所学的知识。与以往不同的是,这次不会提供解决方案,你需要自己探索答案,通过不断尝试和纠错来完善程序。
下面有一个更新后的程序,它用于检查不同年龄段人群所需支付的保险价格。你的任务是将其转换为一个函数,该函数应设置三个字段来接收用户输入:
1. 姓名
2. 年龄
3. 实际保险费用
更新后的代码如下:
Insurance = 1000
age = int(input('Your age: '))
is_old = age > 40
is_young = age <= 28
has_license = input('Do you have a license? ')
if has_license.lower() == 'Yes':
has_license = True
elif has_license.lower() != 'Yes':
has_license = False
if is_old and has_license:
Insurance = Insurance / 2
print("Your insurance cost is ${Insurance}")
elif is_young and has_license:
Insurance = Insurance // 1.50
print("You will need to pay ${Insurance
Python条件与循环深度解析
超级会员免费看
订阅专栏 解锁全文
3278

被折叠的 条评论
为什么被折叠?



