##程序1
def typeint(aim): #这个函数的作用是,如果最后得到了整数,就不会显示X.0
aimf = float(aim)
if aimf == (aimi := int(aim)):
return aimi
else:
return aimf
print("""学生火车票优惠如下:
1、每年的1-3月和7-9月凭学生证可打5折。
2、10人(含10人)以上可打9折。""")
price = float(input("请输入单张火车票的全价:(1~1000):"))
is_student = input("是否为学生(Y/N):")
month = int(input("请输入当前月份(1-12):"))
num = int(input("请输入需要订票的人数:"))
priceall = num * price
if month in (1,2,3,7,8,9) and isstudent in ("Y", "y"):
priceall *= 0.5
if num >= 10:
priceall *= 0.9
print("您应付的金额是:", typeint(priceall))
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/494933350336115.PNG?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
##程序2
try:
score = input("请输入您的成绩:")
if not 100 >= int(score) >= 0: #判断是否在范围内
raise
else:
score = int(score)
except:
print("对不起,您输入的数字不符合要求!")
else:
if score < 60:
get = "不及格"
elif score < 70:
get = "及格"
elif score < 80:
get = "中等"
elif score < 90:
get = "良好"
elif score <= 100:
get = "优秀"
print("您的成绩为:" + get + "!")
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/564461450336165.PNG?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
##程序3
print("机票原价4000元。")
price = 4000
month = int(input("请输入月份:"))
type_ = int(input("输入头等舱(1)或经济舱(2):"))
if 10 >= month >= 5: #旺季
if type_ == 1:
dis = 9
elif type_ == 2:
dis = 7.5
else: #淡季
if type_ == 1:
dis = 6
elif type_ == 2:
dis = 3
print("实际机票价格:", price * (dis / 10), sep = "")
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/432556450336163.PNG?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
如果答案对你有帮助,麻烦给个采纳!