7. Plan your trip! maths issue


#1

is it just me, or is the maths on this stage of the course wrong?
i have filled in the code as instucted and it has passed through seemingly without an issue, but having followed all orders, the maths does not check out, as a trip to Los Angeles for 5 nights with $600 spending money does not come to the accepted $1955 by both codecademy and the interpreter when i did the maths.
is this actually the case or am i just going mad?
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):
cost = 40 * days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost
def trip_cost(city,days,spending_money):
return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days) + spending_money
print trip_cost('Los Angeles',5,600)

the interpreter says this comes to 1955, and any other answer returns "Oops, try again. It looks like the correct value (1955) was not printed." in the bottom left


#2

Show us your math :slight_smile:

600 # spending money
475 # plane ride to Los Angeles
700 # hotel cost for five days
180 # rental car cost for five days with -20 bonus
======
1 955

#3

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
else :
return 0

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

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,500)
# Oops, try again.It looks like the correct value (1955) was not printed.

print trip_cost("Tampa",5,500)
# Oops, try again.It looks like the correct value (1955) was not printed.

print trip_cost("Pittsburgh",5,100)
# Oops, try again.It looks like the correct value (1955) was not printed.

can somebody tell me what 's wrong?..i try to count manually and the result is same with the interpreter but still Oops, try again.It looks like the correct value (1955) was not printed


#4

Problem is in this line:

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

According to instructions it should be 600, not 500 :slight_smile:


#5

it solved..tks mod..by the way I'm from Indonesia thanks and like this learning site:+1::+1::+1:


#6

I am not a moderator but thank you for your kind words. Much appreciated :slight_smile:

You're very welcome!


#7

thank you, when i did the other maths outside of python, i forgot that more than 3 days provides a 20 dollar reduction, much appreciated!


#8

I see :slight_smile: You're very welcome!


#9

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