Taking a Vacation -error- unsupported operand type(s) for -: 'str' and 'int'


#1

Hey guys,

Can you help me with this error?

def rental_car_cost(days):
cost = days * 40
if days >= 7:
return cost - 50
elif days >= 3:
return cost - 20
else:
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 hotel_cost(days):
return 140 * days

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

error -Oops, try again. trip_cost('Pittsburgh', 9) raised an error: unsupported operand type(s) for -: 'str' and 'int'


#2

when the exercise calls the function, the city (for example pittsburg) is the first argument, and days the second. Now look at your function parameters. so in your function, days will hold pittsburgh, and city will be 9. Maybe you should switch your paramters?


#3

Hellou,

Thank you for taking your time to help me.

I am new to programming and also it's not easy learning it using english as a second language. :slight_smile:

Can you write down (the code) what were you trying to explain nicely?

Kind regards,

Marija


#4

look at your function declaration, and then in particular the parameters:

def trip_cost(days, city):

and now the function call by the checking script:

trip_cost('Pittsburgh', 9)

so now look what days and city hold for values:

def trip_cost(days, city):
   print days # will print Pittsburgh
   print city # will print 9

hm... look at all the function you have, days being a string would be catastrophic. Swap the function parameters

English is my second language as well, if you thought i was a native english speaker, you would wrong


#5

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