Write a simple ticket calculator procedure in Python(Python novice must see)

这篇博客介绍了一个简单的Python程序,用于根据旅行月份和选择的舱位计算机票的实际价格。机票价格受旺季和淡季影响,不同舱位折扣不同。在4月至10月的旺季,头等舱打9折,经济舱打6折;而在淡季,头等舱打5折,经济舱同样打6折。通过这个程序,用户可以输入旅行月份和舱位等级,获取实际票价。
摘要由CSDN通过智能技术生成

Task
Suppose you go to a place for a trip,you need book a plane ticket now,Air ticket prices are affected by the high season and low season,and the prices for first class and economy class are also different;
Assuming the ticket costs 5000 yuan,April to October is the peak season.10% off first class and 40% off economy class,50% off first class and 40% off economy class in low season;
Write a program to output the actual fare based on the month of travel and the selected class.

There are programs and simulations in the picture, if the comments are not in place, please come up.

price=0#First, there is no price because user input is required
print("Please enter the month when you plan to travel:1-12")
month=input()#User enters month
m=int(month)#Store the month entered by the user
print("Do you choose first class or economy class? First class input: 1, Economy class input: 2")
level=input()#User input class
l=int(level)#Store the class entered by the user
if (m>=4 and m<=10):#If you travel between April and October, calculate the fare according to the following discount
     if l==1:#10% discount for first class
          price = 5000*0.9
     else:#Otherwise it's Economy Class, 40% off
          price = 5000*0.6
else:#If you are not traveling from April to October, calculate the fare according to the following discount
     if l==1:#50% discount for first class
          price = 5000 * 0.5
     else:#Otherwise it's Economy Class, 40% off
           price = 5000 * 0.4
print("Your ticket price is:",price)

There are programs and simulations in the picture, if the comments are not in place, please come up.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值