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: 3888100 • 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.6e

Explanation / Answer

def price_chart(age, num_pets):  

    whole_string = "Stops Rush Off-Peak"  

    for stops in range (1, 20):  

        in_rush = fare(stops, age, True, False, num_pets)  

        off_rush =  fare(stops, age, False, False, num_pets)  

        whole_string = whole_string+ (" " +str( stops) + " " + str(in_rush) + " " + str(off_rush))  

    print(whole_string)  

          

  

  

def check_rush_hour(day, hour, minute):  

    if hour in range(5, 10, 1) or hour in range(15, 20, 1):  

        if (hour == 9 and minute >= 30) or (hour == 5 and minute < 30):  

            return False  

        else:  

            if (day != "Saturday") or (day != "Sunday"):  

                return True  

            else:  

                return False  

    else:  

        return False  

  

def simple_fare(stops):  

    if stops <= 5:  

        return stops  

    elif stops <= 11:  

        return (5 + ((stops - 5) * (1 / 2)))  

    elif stops > 11:  

        return (5 + 6 * (1 / 2) + ( (stops - 11) * 1 / 4) if ((stops - 11) <= 8)  else (8 * 1 / 4))  

  

  

def fare (num_stops, age, is_rush_hour, want_return_fare, num_pets):  

    if age < 5:  

        return 0  

  

    if is_rush_hour:  

        if age <= 65 and want_return_fare:  

            if num_stops < 11:  

                return 8 + num_pets + simple_fare(num_stops)  

            else:  

                return 12 + num_pets + simple_fare(num_stops)  

        elif age <= 65 and (not want_return_fare):  

            if num_stops < 11:  

                return 8 + num_pets  

            else:  

                return 12 + num_pets  

        elif age > 65 and want_return_fare:  

            if num_stops < 11:  

                return (8 + num_pets) / 2 if ((8 + num_pets) / 2) <= 4 else 4 + simple_fare(num_stops) / 2 if (simple_fare(num_stops) <= 4) else 4  

            else:  

                return (12 + num_pets) / 2 if ((12 + num_pets) / 2 ) <= 4 else 4+  simple_fare(num_stops) / 2 if (simple_fare(num_stops) <= 4) else 4  

        elif age > 65 and (not want_return_fare):  

            if num_stops < 11:  

                return (8 + num_pets) / 2 if ((8 + num_pets) / 2) <= 5 else 4   

            else:  

                 return (12 + num_pets) / 2 if ((12 + num_pets) / 2 ) <= 4 else 4  

    else:  

        if age <= 65 and want_return_fare:  

                return simple_fare(num_stops) + num_pets + simple_fare(num_stops)  

        elif age <= 65 and (not want_return_fare):  

                return simple_fare(num_stops) + num_pets  

        elif age > 65 and want_return_fare:  

            return (simple_fare(num_stops) + num_pets) / 2 if ((simple_fare(num_stops) + num_pets) / 2) <= 4 else 4 + simple_fare(num_stops) / 2 if (simple_fare(num_stops) <= 4) else 4  

        elif age > 65 and (not want_return_fare):  

                return (simple_fare(num_stops) + num_pets) / 2 if ((simple_fare(num_stops) + num_pets) / 2) <= 4 else 4   

  

  

  

price_chart(10, 0)

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