Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please USE only PYTHON to solve the following problem and be sure to follow all

ID: 3888843 • 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.

NOTE: Please make sure the output you get matches the example. The "+" sign needs to be included for the 19 (last line). Thanks

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.6e

Explanation / Answer

def check_rush_hour(day,hour,minute):
    list = ["Monday","Tuesday","Wednesday","Thursday","Friday"]
    if day in list:
       if hour >= 0 and hour <= 23:
         if minute >= 0 and minute <= 59:
           if hour > 5 and hour < 9:
              return True
           if hour == 5:
              if minute >= 30:
                 return True
           if hour == 9:
              if minute < 30:
                 return True
           if hour > 15 and hour < 19:
              return True
           return False
         else:
           print("Invalid data")
           return False
       else:
         print ("Invalid data");
         return False;      
    else:
      return False

def simple_fare(num_stops):
    if num_stops <= 5:
       return num_stops
    else:
       if num_stops <= 11:
          return 5 + (num_stops - 5) * 0.5
       else:
          if num_stops <= 19:
            return 5 + 3.0 + (num_stops - 11) * 0.25
          else:
            return 10

def fare(num_stops, age, is_rush_hour, want_return_fare, num_pets):
   
    if age < 5:
       return 0
    if age >= 65:
       price = num_pets * 1
       if is_rush_hour:
          price = 4
       else:
          price = (price + simple_fare(num_stops))/2
          if price > 4:
             price = 4
       if want_return_fare:
             price = price + price

    if age > 5 and age < 65:
       price = num_pets * 1
       if is_rush_hour:
          if num_stops <= 10:
             price = price + 8
          else:
             price = price + 12
       else:
          price = price + simple_fare(num_stops)
       if want_return_fare:
             price = price + price
    return price

def price_chart(age, num_pets):
    print("Stops "," Rush "," Off-peak ")
    for i in range(19):
        rush_fare = float(fare(i+1, age, True, False, num_pets))
        fare_off = float(simple_fare(i+1)) + num_pets
        if i+1 == 19:
            print("19+", "      $"+str(rush_fare), "       $"+str(fare_off))
        else:
           
            print(i+1, "      $" +str(rush_fare), "       $"+str(fare_off))


print (check_rush_hour("Monday", 6,0))
print (check_rush_hour("Tuesday", 16,15))
print (check_rush_hour("Wednesday", 9,30))
print (check_rush_hour("Friday", 5,30))
print (check_rush_hour("Saturday", 5,30))
print(simple_fare(1))
print(simple_fare(5))
print(simple_fare(6))
print(simple_fare(11))
print(simple_fare(12))
print(simple_fare(30))

print("-------------------")

print(fare(30,3,False,False,0))
print(fare(1,20,False,False,15))
print(fare(5,20,False,False,0))
print(fare(5,20,False,True,0))
print(fare(6,20,False,True,0))
print(fare(5,20,True,False,0))
print(fare(11,20,True,False,0))
print(fare(7,65,False,False,0))
print(fare(7,65,False,True,0))
print(fare(100,65,True,False,0))
print(fare(14,35,False,True,3))
print(fare(14,50,True,False,100))
price_chart(20,5)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote