Need help: Hey, you never know


#1

I keep getting this comment "Oops, try again. trip_cost('Charlotte', 4, 0) raised an error: unsupported operand type(s) for -: 'str' and 'int' "
I do not know where my code is wrong.
can anyone help me?
My code is below

def hotel_cost(days):
return 140 * days

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
else:
return "we do not go there"

def rental_car_cost(days):
cost = 40 * days
if days >= 7:
return cost - 50
elif days >= 3:
return cost - 20
else:
return cost
def spending_cost(cash):
if cash > float(0):
return cash
else:
cash = float(0)
return cash

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


#2

Use only functions and variable names given in the instructions. We should not take liberties with our creativity at this point in the introductory lessons. For best results do exactly as asked.


#3

Thanks for your reply.
I deleted "soending_cost(cash)", but I still cannot get right answer.
I think I follow instructions...
Could any one help me?
My new code is below.

def hotel_cost(days):
return 140 * days

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
else:
return "we do not go there"

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

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


#4

Might not be a problem, but that is not asked for. Remove it so it's out of the picture.

Which order are the first two parameters supposed to be in? The call is,

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

as I recall. The city is the first argument.


#5

Thank you for your help!!!
Finally, I got right answer:)


#6

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