Beijing Metro monthly Consumption total amount calculation (Python version)

Source: Internet
Author: User

Recent spare time in learning Python, this is the day when taking the subway whim, want to see me this one months of the total amount of subway fees, so simple idea of the next idea, directly opened, did not expect to use Python to achieve is quite simple.

Design ideas:

The normal consumption of 7 yuan per ride, 2 times a day by car, 22 days a month on weekdays.

The total monthly travel amount exceeds 100 yuan, the next 80 percent of the fare

The total monthly travel amount exceeds 150 yuan, the next 50 percent of the fare

The total monthly car amount exceeds 400 yuan, next bus does not discount

Code:

1 #_*_coding=utf-8 _*_2 __author__='Xue'3  4  5 " "6 calculate the total monthly fare of Beijing Metro7 Version 1.08 default: X Yuan per ride, Drive 2 times a day, 22 days a month by car9  Ten The total monthly travel amount exceeds 100 yuan, the next 80 percent of the fare One The total monthly travel amount exceeds 150 yuan, the next 50 percent of the fare A The total monthly car amount exceeds 400 yuan, next bus does not discount -   - " " the   - def(): -Daymoney=int (Raw_input ("Please enter your normal fare per ride (unit: RMB):")) -Daytime=raw_input ("Please enter your daily number of rides (default 2 times):") +Daymonth=raw_input ("Please enter your monthly travel days (default 22 days):") -dayallmoney=0.0#Total car amount for the month +   A     #statistics on the amount and frequency of rides in each stage and atm100=0.0 -m150=0.0 -m400=0.0 -mmax=0.0 -t100=0 -t150=0 int400=0 -tmax=0 to   +     ifdaytime=="': -daytime=2 the     Else: *Daytime=int (Daytime)#Format Conversion $  Panax Notoginseng     ifdaymonth=="': -Daymonth=22 the     Else: +Daymonth=int (Daymonth)#Format Conversion A   theDaymonthtime=daytime*daymonth#total number of rides per month +Daynowtime=0#number of rides recorded -   $      whiledaynowtime<=Daymonthtime: $   -         ifdayallmoney<=100.0:#when the total amount is equal to 100 yuan, the normal fare is charged -dayallmoney+=Daymoney them100+=Daymoney -T100+=1Wuyi         elifdayallmoney<=150.0:#when the total amount is equal to 150, it is charged at 80 percent of the normal fare. thedayallmoney+=daymoney*0.8 -m150+=daymoney*0.8 WuT150+=1 -         elifdayallmoney<=400.0:#when the total amount is equal to 400, it is charged at 50 percent of the normal fare. Aboutdayallmoney+=daymoney*0.5 $m400+=daymoney*0.5 -T400+=1 -         Else:#The total amount is more than 400 yuan, according to normal fare charge -dayallmoney+=Daymoney Ammax+=Daymoney +Tmax+=1 the   -   $Daynowtime+=1#Number of rides + + the   the     return(Daymonth,daytime,daymoney,dayallmoney,m100,t100,m150,t150,m400,t400,mmax,tmax) the   the   - if __name__=='__main__': in(Dm,dt,dy,dam,m100,t100,m150,t150,m400,t400,mmax,tmax) =() the   the     Print("\ n") About     Print("you take the Beijing subway in the month of {0} days, every day {1} times, a single ride consumption {2} yuan, a total consumption of {3:.2f} yuan. ". Format (dm,dt,dy,dam)) the     Print("\ n") the     Print("total monthly consumption limit of 100 yuan period: Total ride {0} times, phase consumption {1:.2f} yuan, total {2:.2f} yuan. ". Format (t100,m100,m100)) the     Print("total monthly consumption limit of 150 yuan period: Total ride {0} times, phase consumption {1:.2f} yuan, total {2:.2f} yuan. ". Format (t150,m150,m100+m150)) +     Print("total monthly consumption limit of 400 yuan period: Total ride {0} times, phase consumption {1:.2f} yuan, total {2:.2f} yuan. ". Format (t400,m400,m100+m150+m400)) -     Print("Total monthly consumption of more than 400 yuan stage: Total ride {0} times, phase consumption {1:.2f} yuan, total {2:.2f} yuan. ". Format (tmax,mmax,m100+m150+m400+Mmax)) the     Print("\ n")

Test results:

Beijing Metro monthly Consumption total amount calculation (Python version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.