Taking a Vacation 6/7 - Unsupported Operand Type


#1

I’m not sure what’s wrong with my code here. The error message “unsupported operand type” isn’t narrowing things down for me. Do I need to define spending_money? Seems like I have my three variables (City, Days, Spending Money) inputted correctly…

Trip%20Cost%202

Trip%20Cost%201


#2

Check line 21 for the type discrepancies.


#3

print trip_cost(“Los Angeles”, “5”, “600”)

I altered the spacing of line 21 so that print is aligned with return from line 20, but that didn’t do the trick. I also tried removing the quotes around the three variables (Los Angeles, 5, 600) but now I’m getting an invalid syntax error. I don’t see what else I can change in that line :thinking:


#4

def trip_cost(city, days, spending_money):
return rental_car_cost(days) + hotel_cost(days - 1) + plane_ride_cost(city) + spending_money
print trip_cost(“Los Angeles, 5, 600”)

I’ve gotten a green check for the lesson, but I still can’t get anything to print, so I’m not confident that my coding is correct. I’m not seeing any discrepancies in that line :man_shrugging:


#5
(Los Angeles, 5, 600)
 ----str---- int int

Only the str type needs to be in quotes.


#6

I can’t figure out how to nights (for hotel cost) in terms of days (nights = days - 1). In my code I tried to avoid the nights variable and just use hotel_cost(days - 1) but that isn’t working. Can you help me figure out how to bridge these variables? (night and day)


#7

nights is only a local variable of the hotel_cost function. days is a local variable of the trip_cost function. When days - 1 is used as an argument in the call to hotel_cost, it is passed to the nights variable.

Be sure not to use nights as a parameter of trip_cost, just days.


#8

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