Please USE only PYTHON to solve the following problem and be sure to follow all
ID: 3885281 • Letter: P
Question
Please USE only PYTHON to solve the following problem and be sure to follow all instructions carefully. Thank you.
The template as provided below is for your reference:
The following info is for your reference only. No need to solve the problem below. Please read all instructions carefully. Thank you.
price_chart (age, num_pets): This function creates a multi-line string showing one-way prices for rush hour and non-rush hour in a chart-like fashion. The columns are labeled Stops (from 1 through "19+"), Rush pricing (for that age and number of pets), and off-peak for non-rush hour pricing (for that age and number of pets). There are always 20 lines (header line and 19 stop-prices), with a single tab between items on a line. All prices should be floats (we see S1.0 instead of S1). Below are some examples; use the tester examples for further guidance on exact formatting. age and num_pets are both non-negative int values. Loops are recommended for your solution but are not required. This function returns a string, but printing it makes it easier to see the purpose; thus we mostly call print(price_chart()) below . >>>price chart (18,) »>print (price chart(70,0)) Stops Rush Off-peak $4.0 $8.5 2 $4.0 $1.0 3 $4.0 $1.5 4 $4.0 $2.e t$8.25 13 $12.0 $8.5in14t$12.t$8.75 15 $ 12.t$9.8 16t$12. $9.25 17 $12.8 $9.5 18) t$12.t$9.75 19+1t$12.8 $10, ' >>>print(price chart (1e,)) Stops Rush Off-peak $4.0 $2.5 6 $4.0 $2.75 7 $4.0 $3.e 8 $4.0 $3.25 9 $4.0 $3.5 10 $4.0 $3.75 11 $4.0 $4.6e 12 $4.0 $4.0 13 $4.0 $4.6e 14 $4.0 $4.60 15 $4.0 $4.e 16 $4. $4.6e 17 $4.0 $4.6e 18 $4.0 $4.6e 19 $4.0 $4.6e $8.0 $1.0 2 $8.0 $2.e 3 $8.0 $3.0 4 $8.0 $4.6e $8.0 $5.0 6 $8.e $5.5 7 $8.e $6.0 8 $8.0 $6.5 10 $8.0 $7.5 11 $12.0 $8. 12 $12.0 $8.25 13 $12.0 $8.5 14 $12.0 $8.75 15 $12.0 $9.e 16 $12.8 $9.25 17 $12.0 $9.5 18 $12.0 $9.75 19+ $12.0 $18.0 >> print (price_chart(2,0)) Stops Rush off-peak 1 $8.0 $e.8 2 $0.0 $0.e 4$0.9$0.0 5 $0.0 $0.e 6 7 $0.0 $0.8 >>> print (price_chart (20,5)) Stops Rush Off-peak 1$13.0 $6.0 2 $13.0 $7.8 3 $13.0 $8.0 4 $13.0 $9.e 5 $13.0 $10.0 6 $13.0 $10.5 7 $13.0 $11.0 8 $13.0 $11.5 9 $13.0 $12.e 10 $13.0 $12.5 11 $17.9 $13.0 12 17.0 $13.25 13 $17.0 $13.5 14 17.0 $13.75 15 $17.0 $14.0 16 $17.8 $14.25 17 $17.0 $14.5 18 $17.0 $14.75 19+ $17.0 $15.0 9 $0.0 $0.e 10 $0.0 $0.e 11 $0.0 $0.e 12 $0.0 $0.e 13 $0.0 $0.6e 14 $0.0 $0.0 16 $0.0 $8.0 17 $0.9 $0.0 18 $e.0 $0.e 19 $0.0 $0.6eExplanation / Answer
#PYTHON 3.6.2
#for checking the rush prices
# this method returns the fare according you told
def simple_fare(num_stops,rush):
if rush==0:
if num_stops<=5 and num_stops>0:
return (num_stops+0.0)
if num_stops <=11 and num_stops>5:
i=5.0+(num_stops-5)*0.5 #formula for calculating price from 5 to 11
return i
if num_stops>11 and num_stops<=19:
i=8.0+(num_stops-11)*0.25 #formula for calculating price from 12 to 19
return i
if num_stops>19:
i=10.0
return i
if rush==1:
if num_stops>0 and num_stops<=10:
return 8.0
else:
return 16.0
#for printinf price chart
def price_chart(age,num_pets):
if num_pets==0:
if age<=5: #for age <5
for i in range(1,20):
print (str(i) +' ' + '0.0$'+' '+'0.0$')
if age>=65: #for age >65
for i in range(1,11):
print (str(i) +' ' + str(simple_fare(i,1)/2)+'$ '+str(simple_fare(i,0)/2)+'$')
for i in range(11,20):
print (str(i) +' ' + '4.0$'+' '+'4.0$')
if age>5 and age<65: #for age >5 and <65
for i in range(1,20):
print (str(i) +' ' + str(simple_fare(i,1))+'$ '+str(simple_fare(i,0)))
if num_pets>0:
if age<=5 and age>0: #for age <5
for i in range(1,20):
print (str(i) +' ' + '0.0$'+' '+'0.0$')
if age>=65: #for age >65
for i in range(1,11):
print (str(i) +' ' + str(simple_fare(i,1)/2+num_pets)+'$ '+str(simple_fare(i,0)/2+num_pets)+'$')
for i in range(11,20):
print (str(i) +' ' + str(4.0+num_pets)+'$ '+str(4.0+num_pets)+'$')
if age>5 and age<65: #for age >5 and <65
for i in range(1,20):
print (str(i) +' ' + str(simple_fare(i,1)+num_pets)+'$ '+str(simple_fare(i,0)+num_pets)+'$')
print('welcome to the price calculator' )
print ('please enter the fllowing details')
print('please enter the age')
age=input()
a=int(age) #for changing it into integer
print ('please enter the num_pets')
num_pets=input()
print ('Sr.No. Rush Off peak')
n=int(num_pets)
price_chart(a,n)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.