mardi 8 août 2017

How to correct the output of of a function?

I'm writing a function that will return the total cost of a trip, but I keep getting the wrong output whenever I put "Charlotte" and any number as arguments for the trip_cost function. When I put trip_cost('Charlotte', 6) for example, the software that checks for the right answer keeps telling me that the function produces 1240 instead of 1243.

Can anyone give me tips on how to correct the following code?

   def hotel_cost(nights):
   cost = 140 * nights
   return cost

   def plane_ride_cost(city):
   if city == "Charlotte": 
   return 183
   elif city == "Tampa":
   return 220
   elif city == "Pittsburgh":
   return 222
   elif city == "Los Angeles":
   return 475

   def rental_car_cost(days):
   cost = 40 * days
   if days >= 7:
   cost -= 50
   elif days >= 3 and days < 7:
   cost -= 20
   return cost

   def trip_cost(city, days):
   total = rental_car_cost(days) + hotel_cost(days) + 
   plan_ride_cost(city) 
   return total 

Aucun commentaire:

Enregistrer un commentaire