Taking Vacation: Transport


This is the code that i wrote:
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):
total == days*40
if days >= 7:
total += 50
elif days >= 3:
total += 20
return total

And it is returning error:
Oops, try again. An error was raised for rental_car_cost(1): local variable 'total' referenced before assignment.


This line..

total == days*40

seems something out of structure?
We have learned about assignment operator (=)if we want to save(to make connection between variable name and value) a value to a variable, we use it.

This line..

total += 50
Discount means the value we pay will reduce (here by 50) but its increasing our total?
There is same problem in elif block.


Got it, thanks a lot !!!!!!!! :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.