7/7 Taking a Vacation unsupported operand type(s)


#1

I can't figure out what's wrong. It says:

Traceback (most recent call last):
File "python", line 22, in
File "python", line 20, in trip_cost
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

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
def trip_cost(city, days, spending_money):
return hotel_cost(days)+rental_car_cost(days)+plane_ride_cost(city)+spending_money

print trip_cost("Lost Angeles", 5, 600)

Btw was scrolling through other Q&A's and yes my final print is NOT indented and I believe my entire code is indented properly but please correct me if indentation is actually the problem.


#2

@nanodino,

Have a close look at

Lost Angeles


#3

Thank you so much! That was my problem also. LOL


#4

does anyone know what is wrong with this block of code?

def trip_cost(city,days, spending_money):
return plane_ride_cost(city) + rental_car_cost(days) +hotel_cost(days) + spending_money
print trip_cost("Los Angeles", 5 , 600)

it keeps returning no value


#5

@danielj1988,
Have you tried a reset of your Browser

++++ reset of session *****************
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom


#6

Great..cache issue..ThankU


#7

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

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

def hotel_cost(days):
return days * 140

def trip_cost(city,days, spending_money):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)+spending_money

print trip_cost("Los Angeles", 5, 600)


#8

You have to call the function after the return. We also have learned that space matters. Make a new line between the function and than call the function.

......
return(...)

print trip_cost("Los Angeles", 5 , 600)