Files
2025PY/day07/05-作业.py
2025-05-22 16:50:44 +08:00

41 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 一.请输入一个km数值计算打车费用已知出租车起步价10块钱3km以内超出的部分2元/km
# 分析
# 判断你输入的km数字是否>3
# num = int(input('请输入一个公里数km:')) # 输入的公里数
# if num > 3: # 起步价 + 超出的公里数 * 2 (2元/km)
# print(f'你输入的公里数是{num},打车费用是{10 + ( num - 3 ) * 2}')
# elif num == 0:
# print(f'你输入的公里数是{num},没有打车费用')
# else:
# print(f'你输入的公里数是{num},打车费用是起步价10元')
# 二.程序题
"""
东方航空从北京飞往马尔代夫的机票原价为4000元,4到10月份为旺季, 其他月份为淡季,
- 旺季时候头等舱打9折,经济舱打7.5折;
- 淡季头等舱打6折, 经济舱打3折。
- 从页面输入出行的月份和选择的舱型计算出机票价格
"""
# 分析条件
# 条件4-10月旺季. 其他的是淡季
# 条件:头等舱 经济舱
# 代码演示
# 输入月份和选择的舱型
month = int(input('请输入出行的月份(1 - 12):')) # 输入的月份
level = input('请输入你选择的舱型(头等舱/经济舱):') # 输入的舱型
price = 4000 # 机票的价格
# 通过条件判断是旺季还是淡季
if month >= 4 and month <= 10 : # 旺季
# 继续判断是头等舱还是经济舱
if level == '头等舱':
print(f'旺季头等舱的价格是{price * 0.9}') # 旺季头等舱打九折
else :
print(f'旺季经济舱的价格是{price * 0.75}') # 旺季经济舱打七五折
else: # 淡季
# 淡季头等舱打6折, 经济舱打3折
if level == '头等舱':
print(f'淡季头等舱的价格是{price * 0.6}') # 淡季头等舱打六折
else :
print(f'淡季经济舱的价格是{price * 0.3}') # 淡季经济舱打三折