Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with python Task Tasks We are calculating ticket prices for riding the metro. There are very specific rules and conditions that affect overall price;

Help with python Task

image text in transcribed

Tasks We are calculating ticket prices for riding the metro. There are very specific rules and conditions that affect overall price; we first have a simpler version, and then a larger version (which can optionally re-use your simpler version if it helps). check_rush hour (day, hour, minute): Given what time it is, determines if the moment is during a rush hour or not. This answer is returned as a bool. We define rush hours as from 5:30am to 9:30am, and from 3:00pm to 7:00pm, on weekdays only (start time is part of rush hour stop time is not) assume: day is a string like "Sunday", and will only be a valid day. hour is an int from 0 to 23; minute is an int from 0 to 59 check-rush-hour( "Monday", 6, check-rush-hour( "Tuesday", 16, check-rush-hour( "Wednesday", 9, check-rush-hour( "Friday", 5, check-rush-hour( "Saturday", 17, e)-True 15)-True 30) False 30) True e)-False #during morning rush, 6:00am #during evening rush, 4:15pm #stop time not part of rush hour #during rush hour on a weekday #not a weekday, would have been otherwise simple_fare (num_stops):Given the number of stops, calculates the simple fare. Each stop adds some amount to the price: the first five stops add $1 each; the next 6 add 50 each; the next 8 stops add 25 each; any additional stops are free. Assume num_stops is a non-negative int simple-fare(1) simple fare(5) 5 simple-fare(6) simple-fare(11) simple-fare(12) simple-fare(30) 1 5.5 8.25 # each stop cost $1 # first five stops were $1, next stop was only 504 #five @ $1, 6 @ 504 #five @ $1, 6 @ 504, 1@254 # Lots of free stops; this is the maximum fare . 10 fare (num_stops, age, is_rush_hour, want_return fare, num_pets): Given how far to go, how old the passenger is, whether it's rush hour or not, whether they want to purchase a return fare at current prices, and how many pets they are bringing with them, calculate the full price according to the following rules kids under age 5 ride any distance free each transported pet adds S1 per ride, regardless of distance or age or rush hour in rush hour, 0-10 stops costs $8 for the distance, all longer trips cost S12. outside of rush hour, pricing is the exact same as with simple_fare (it's quite possible to call that function and reuse its efforts!) a return ticket may be purchased at the same time for the same price. (perhaps we could leave after morning rush hour but return cheaply during evening rush hour by buying the ticket off-peak). senior citizens (age 65+) pay half as much for the distance/pet choice, never paying more than $4 per ride (including pet costs), even during rush hour. (fare for return ride may also cost up to $4). don't worry about returning e.g. 3 Vs 3.0; when we check equality they are considered equal. o o o o o o o False, False, False, False, False, True, True, False, False, True, False, True, False, ) False, 15) False, ) True, ) True, ) False, ) False, e) False, ) True, ) False, ) True, 3) False, 100) 16 5 10 11 8 fare(30, 3, fare( 1, 2e, fare( 5, 28, fare( 5, 2e, fare( 6, 2e, fare( 5, 20, fare(11,20, fare( 7, 65, fare( 7, 65, fare (100,65, fare(14, 35, fare(14, 50, # kids ride free # $1 ride plus 15*$1 for pet transport= $16 # same rules as simple-fare # buying return fare, 5+5-Se # 5592=-$11; buying a cheap ticket for the ride home! # rush hour pricing # rush hour pricing # senior citizen pays half of the usual $6 fare # twice the cost of senior going 7 stops # even during rush hour seniors never pay over $4 3 6 4 23.5 # combination of rules: 8.75+3pets, two trips 112 # combination of rules: rush hour with lots of pets

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

c. How is trust demonstrated?

Answered: 1 week ago