def hotel_cost(nights): return 140 * nights 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 else: return cost None Oops, try again. An error was raised for rental_car_cost(1): local variable 'cost' referenced before assignment I have no idea what I am doing wrong, if someone could please help me to understand what is going wrong. Help a pal out... Thanks.
cost == 40 * days
what is it suppose to do? (yes, i know what its suppose to do, but i would like to hear it from you)
It means the cost of the rental car is equal to how many days the car is rented multiplied by the cost of the car ($40).
but cost is not yet defined, so how can it equal something?
usually we use is equal inside conditions (like
elif), but in your case its not a condition?
The purpose of your function is to calculate how much it would cost to rent the car for
x days.This means you need to calculate the $40 * days, then apply discount, then return the total cost for renting a car
Okay, I think I get it. Thanks!
i edited my earlier answer
So it would make sense to multiply $40 * days, and then store this in a variable. Then we can see if we need to apply discount, then finally we can return cost
If you need more help, post an updated version of your code
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.