What am I doing wrong?


#1



yeah I'm at a loss for words as to why the error I get happens, the code gives the correct answer.

It doesn't give me a line the error occurred on.


this is the error that I get.

Oops, try again. trip_cost should take exactly three parameters: city, days, and spending_money (in that order).


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

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

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

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


#2

Hi @allenburley91,

What does the rental_car_cost function return if days is equal to 1?


#3

it should return 40.
lines 20 & 21
days*40 if days = 1 then it would be return 1*40 and give me 40


#4

You have ...

    elif days>=2:
        return days*40

The condition, days>=2, would be False if days were equal to 1, so the return statement would not execute.


#5

well now I have a new problem to work out hehe, thanks for the help so far though.


#6

Instead of this ...

    elif days>=2:

... you could go with this, in order to catch anything that does not satisfy the previous conditions...

    else:

#7

I have altered it to be as follows

else days>1 and days<2:
days*40

and now it gives me syntax errors:
File "python", line 19
else days>1 and days<2:
^
SyntaxError: invalid syntax


#8

The else header should not contain a condition. This is incorrect ...

    else days>1 and days<2:

It should be simply ...

    else:

If the if and all elif conditions are False, then the else block will execute as the default. In the rental_car_cost function, that would occur whenever days is less than 3.


#9

for one day i'm getting a new error.

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

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

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

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

error is as follows

Traceback (most recent call last):
File "python", line 25, in
File "python", line 23, in trip_cost
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

ps sorry about not being able to get the indents to show for some reason.


#10

I'm not sure if this will help, but, for my code, I used this:

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

So, instead of a second elif, or a separate else statement, the cost for (1) day is already defined from the beginning with

rental_car_cost = days * 40

The cost is saved in a variable that just gets updated as input is taken in. It's a little more typing, but it simplified it for my understanding


#11

I will try that , thanks


#12

well that solved the first issue now it's giving me the wrong answer >.<

well for one day the answer was wrong but 5 days it passed


#13

What's your code? And what answer is being returned?


#14

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

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

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

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

and it gives me 1255, and the lesson says it should give me 1955, but the answer is right for one day... it's wierd, swapping back to 5 days and see if it let me pass

it's wierd because the cost is 1255 for a single day**


#15

yeah the lesson was acting weird about me trying to figure out the one day , had to do the math myself, I found out what I was doing wrong for the initial part. The course only wanted the 5 day total so I didn't double check it when it said my answer was wrong.


#16

Ah! Yes. I just went back and re-did the math on mines. Codecademy is strict on it's instructions, but if you were to run this independently it would work :stuck_out_tongue:

Happy learnings :smiley:


#17