Yoohoo! can anyone help me! something is wrong with my code!


#1



8.Taking a Vacation


This is the error:
Oops, try again. trip_cost('Tampa', 5, 0) returned 450 instead of the correct value 1100
There are also other errors but this is the one that i cant seem to figure out,


I EXPECT IT TO WORK!!!!


def hotel_cost(nights):
    nights== nights > 0
    tom = nights * 140
    return tom
    
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 "Sorry, don't know this one. Did you type one of the cities from the list?"
    
    
def rental_car_cost(days):
    rent = 40 * days
    if days > 6:
        rent -= 50
    elif 7 > days > 2:
        rent -= 20
    return rent
    
    
def spending_money(days):
    days > 0
    return 10 * days
    
        
def trip_cost(city, days ,nights):
    return rental_car_cost(days) + plane_ride_cost(city) + spending_money(days)+ hotel_cost(nights)


#2

What where you trying to do here? Take a look at these:

Also, I'm not sure this would work fine:
elif 7 > days > 2:
Maybe it turned out to be complicated or messy, but think you can easily ask in the condition if a number is >= than another number.

Syntax aside, I think the def of trip_cost was the main problem. Aren't those days and nights parameters the same, actually? In the instructions they ask you:

Modify your trip_cost function definition. Add a third argument, spending_money.

So codecademy (when testing your code) is expecting these arguments to show: trip_cost(city, days, spending_money). spending_money is a straight number, and altough your spending_money(days) function was interesting, I don't think they'll let you pass the course because they're expecting it to be something different.


#3

Thank you,
I would type in "elif 7 > days >2" because it would tell me that i have not defined the days function and the night function and everything else seemed to be in order so i assumed that the computer did not know what the days function was.
I replaced the elif 7 > days > 2 with "elif days > 2 and days < 7". It still was not working and came up with similar syntax errors.
It is still coming up with the same syntax .


#4

Would you post an updated version of your code?


#5

def hotel_cost(nights):
** tom = nights * 140**
** return tom**


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 "Sorry, don't know this one. Did you type one of the cities from the list?"**



def rental_car_cost(days):
** rent = 40 * days**
** if days > 6:**
** rent -= 50**
** elif 7 > days > 2:**
** rent -= 20**
** return rent**



def spending_money(days):
** return 50 * days**



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

__The bottom line is all one statement - it just does not fit in one line.


#6

Where?

It'd be awesome if you formatted your code here! Just select the code and press the < / > button! Or read this guide to understand it better.

Back to your code, you improved those missing if statements, that's good. But you're quite not grasping the task in the trip_cost function yet.
Will you read again what I said about it before? Because I don't really know how to rephrase it, maybe if you had some specific questions we'd figure it out. But you're in the way to success, so don't give up ok? :smile:


#7

Thanks, i tried to update the code and used </> to show the indentation in the code. Now the code comes up with a new syntax which is "Oops, try again. trip_cost('Tampa', 8, 0) raised an error: 'int' object is not callable." Also if in the trip_cost function i put 500 instead of spending money, then it comes up with the syntax that nights is not defined.

def hotel_cost(nights):
</>tom = nights * 140
</></>return tom

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 "Sorry, don't know this one. Did you type one of the cities from the list?"

def rental_car_cost(days):
</> rent = 40 * days
</> if days > 6:
</></> rent -= 50
</> elif days > 2 and days < 7:
</></>rent -= 20
</>return rent

def spending_money():
</> return 500

def trip_cost(city, days ,spending_money):
</> return rental_car_cost(days) + plane_ride_cost(city) + spending_money()+ hotel_cost(nights)


#8

def hotel_cost(nights):
    tom = nights * 140
    return tom
    
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 "Sorry, don't know this one. Did you type one of the cities from the list?"
    
    
def rental_car_cost(days):
    rent = 40 * days
    if days > 6:
        rent -= 50
    elif days > 2 and days < 7:
        rent -= 20
    return rent
    
    
def spending_money():
    return 500
    
        
def trip_cost(city, days ,spending_money):
    return rental_car_cost(days) + plane_ride_cost(city) + spending_money()+ hotel_cost(nights)

#9

Your trip_cost is better, you got the instructions right.

But then I also explained that spending_money is "a straight number", meaning that it's meant to be an argument, a parameter. It's not meant to be a function, and that is how you defined it.
spending_money is an integer, same as days, that's going to be sent when someone calls your trip_cost function.

Good luck! Share your updated code if you're stuck.


#10

It is still not working, here is the syntax error: Oops, try again. trip_cost('Tampa', 7, 0) raised an error: 'int' object is not callable.
Here is my code:

def hotel_cost(nights):
    tom = nights * 140
    return tom
    
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 "Sorry, don't know this one. Did you type one of the cities from the list?"
    
    
def rental_car_cost(days):
    rent = 40 * days
    if days > 6:
        rent -= 50
    elif days > 2 and days < 7:
        rent -= 20
    return rent
    
    
def spending_money():
    return 500
    
        
def trip_cost(city, days ,spending_money):
    return rental_car_cost(days) + plane_ride_cost(city) + spending_money()+ hotel_cost(nights)

#11

Ok. Why are you defining a spending_money() function here? What's it purpose? I mean, if it's just returning always the same amount it's not very useful, since you'll apparently be spending always the same money ($500), wether you're travelling 2 days or 200 days. Right?

The thing is, that function is not necessary -at least in this course- and it's not asked for you to create it in the instructions.

I love creativity, it's just it's not going to do here and it wont let you pass the lesson, since you're not doing it exactly how it's asked.

-
Notice that inside trip_cost you are not calling the spending_money parameter, but the spending_money() function. There's a huge difference. Use the parameter that's given to you, and forget about that function.


#13

Not sure what stage you are on in the lesson, but there is no need to define the spending_money function for the purposes of the lesson. On the final stage, you will simply insert the value in the the final print command. Also, hotel_cost in the trip_cost function will need to call (days) like the instructions state. No need to change the argument in the original function.


#14

As @root4af and @jnb7 have explained, the name spending_money refers to a number, and should not be coded as a function. It represents an amount of money that is not computed based on the location or duration of the trip, and therefore does not rely upon a function argument.

Remove the spending_money function definition, and remove the parentheses from this statement that present spending_money as part of a function call ...

return rental_car_cost(days) + plane_ride_cost(city) + spending_money()+ hotel_cost(nights)

Also, instead of the making the function call, hotel_cost(nights), in the above, you should pass days as the function argument. The duration of the trip in 24-hour days is the same as the number of nights.


#15

Thanks for the help:I tried to update my code to make spending_money just a variable and not a function (i hope that is right) but this problem is completely different. I have been going over my code for ages an now the console has a problem with the first line: it says in the console:
Oops, try again. trip_cost('Charlotte', 7, 0) raised an error: unsupported operand type(s) for -=: 'str' and 'int'

Here is my code:

def hotel_cost(nights):
    nights *= 140
    return 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 "Sorry, don't know this one. Did you type one of the cities from the list?"
    
    
def rental_car_cost(days):
    rent = 40 * days
    if days > 6:
        rent -= 50
    elif days > 2 and days < 7:
        rent -= 20
    return rent
    
    
spending_money = 500
    
        
def trip_cost(days, city ,nights):
    return rental_car_cost(days) + plane_ride_cost(city) + spending_money + hotel_cost(nights)

#16

Thanks for the help: But i have done that and it still not seem to be working.I tried to update my code to make spending_money just a variable and not a function (i hope that is right) but this problem is completely different. I have been going over my code for ages an now the console has a problem with the first line: it says in the console:
Oops, try again. trip_cost('Charlotte', 7, 0) raised an error: unsupported operand type(s) for -=: 'str' and 'int'

Here is my code:

def hotel_cost(nights):
    nights *= 140
    return 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 "Sorry, don't know this one. Did you type one of the cities from the list?"
    
    
def rental_car_cost(days):
    rent = 40 * days
    if days > 6:
        rent -= 50
    elif days > 2 and days < 7:
        rent -= 20
    return rent
    
    
spending_money = 500
    
        
def trip_cost(days, city ,nights):
    return rental_car_cost(days) + plane_ride_cost(city) + spending_money + hotel_cost(nights)

#17

Thanks for the help: I am not sure what is wrong now.I tried to update my code to make spending_money just a variable and not a function (i hope that is right) but this problem is completely different. I have been going over my code for ages an now the console has a problem with the first line: it says in the console:
Oops, try again. trip_cost('Charlotte', 7, 0) raised an error: unsupported operand type(s) for -=: 'str' and 'int'

Here is my code:

def hotel_cost(nights):
    nights *= 140
    return 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 "Sorry, don't know this one. Did you type one of the cities from the list?"
    
    
def rental_car_cost(days):
    rent = 40 * days
    if days > 6:
        rent -= 50
    elif days > 2 and days < 7:
        rent -= 20
    return rent
    
    
spending_money = 500
    
        
def trip_cost(days, city ,nights):
    return rental_car_cost(days) + plane_ride_cost(city) + spending_money + hotel_cost(nights)

#18

You changed the hotel_cost function, which follows, and now it no longer works ...

def hotel_cost(nights):
    nights *= 140
    return nights

Check Planning Your Trip.

You have this ...

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

Does it fully conform to the specifications provided in the Pull it Together and Hey, You Never Know! exercise instructions?

Check the number and order of the function parameters and the names of the variables.


#19

I am still confused because i edited the hotel_cost function to look like this:

def hotel_cost(nights):
    return nights * 140

but it still has the error in the console:

File "python", line 2
return (nights * 140)
...................... ^
SyntaxError: invalid syntax
`

I am not sure what you are trying to say at the end as you say:

The spending money variable is there because other people have told me that it should not be a function but rather just have a value. I do not know what is wrong with it now


#20

From the Pull it Together exercise instructions ...

Below your existing code, define a function called trip_cost that takes two arguments, city and days.

The city and days parameters should be in the order given above. There should be no nights parameter.

The Hey, You Never Know! exercise instructions include this ...

Modify your trip_cost function definition. Add a third argument, spending_money.

Then your function header should be ...

def trip_cost(city, days, spending_money):

The order of the parameters is important. Codecademy's test requires them to be in that order.

Within the function, you have ...

return rental_car_cost(days) + plane_ride_cost(city) + spending_money + hotel_cost(nights)

However, the Pull it Together exercise instructions point out that ...

It is completely valid to call the hotel_cost(nights) function with the variable days.

We do not have a variable, nights, defined within the trip_cost function, however our variable, days, has the same value as the number of nights of the hotel stay. Therefore, inside the function, you should instead have ...

return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days) + spending_money

#21

2 posts were split to a new topic: Taking a Vacation: Indentation Error