I can't figure it out | Hey, You Never Know!


#1

So here is my code:
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):
price = days*40
if days >= 7:
price = (days*40) - 50
elif days >= 3:
price = (days*40) - 20
return price
def trip_cost(city, days):
return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)
print trip_cost("Pittsburgh", 10)


It keeps saying

"Oops, try again. trip_cost should take exactly 3 arguments!"

I mean, I thought it already has 3 arguments, I don't know how else I can put up with seeing that evil red message over and over again, please help!


#2

I came up with this

def trip_cost(city, cost, days):
return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)
print trip_cost("Pittsburgh",5,10)

But it just keeps generating random results for the problems, can someone please help?


#3

Could you post the entire code? It's hard to see where the problem could be if I don't know where the variables are being defined.


#4

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):
price = days*40
if days >= 7:
price = (days*40) - 50
elif days >= 3:
price = (days*40) - 20
return price
def trip_cost(city, cost, days):
return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)
print trip_cost("Pittsburgh",5,10)


#5

Alright, can I also get you to post the Error message and exactly which lesson, Chapter, Language you're on?


#6

Oops, try again. trip_cost('Pittsburgh', 6, 0) returned 222 instead of the correct value 1282

but it keeps generating random variables for the error message for some reason, it's so weird.

Python > Taking a Vacation > 6.) Hey you never know!


#7

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):
    price = days*40
    if days >= 7:
        price = (days*40) - 50
    elif days >= 3:
        price = (days*40) - 20
    return price
def trip_cost(city, days):
    return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)
    print trip_cost("Pittsburgh", 10)
def trip_cost(city, cost, days):
        return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)
print trip_cost("Pittsburgh",5,10)

#8

Switch "Pittsburgh" to "Los Angeles".


#9

https://www.codecademy.com/courses/python-beginner-P5YtY/1/6?curriculum_id=4f89dab3d788890003000096

Following the instruction as requested "Los Angeles",5, 10 you will print on the console 1955 instead of 1112, the result for "Pittsburg", 5, 10

That's why returned 1112 instead of corect value 1955 .

1955 is the correct value you should print on the console if you follow the instruction EXACTLY as requested "Los Angeles", 5 , 600.

https://www.codecademy.com/courses/python-beginner-P5YtY/1/6?curriculum_id=4f89dab3d788890003000096
It looks like the correct value (1955) was not printed.

Of course, you can change the arguments of the function trip_cost with "Pittsburgh" , 5, 10 it doesn't mean that is an error.
If you want you "can go" with YOUR code to Pittsburg for 5 days and with 10$.But who made the Python lesson wants US all to go Los Angeles for 5 days with 600$ spending money. Got it? I hope it was useful my explanation.
Have a funny coding day!


#10

here is the code:::: ::slight_smile:
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):
return total - 50
elif(days>=3):
return total - 20
else:
return total
def money(money):
return money

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


#11

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):
return total - 50
elif(days>=3):
return total - 20
else:
return total
def money(money):
return money

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