Transportation Code error


#1



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


File "python", line 18
return total=total - 50
^
SyntaxError: invalid syntax


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


#2

You do not need to return this, just

return total - 50

Also do this for this line:

additionally, why are you indented so much? Python is EXTREMELY meticulous about indenting, so shift+tab everything inside of the function rental_car_cost.


#3

now the code gives error " Did you create a function called rental_car_cost?" :frowning: I do indent to make it readable for me ( I'm new in coding)

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

#4

No, it's good to indent, I'm saying you indented one indent too far lol.
I think your only problem is that you don't have else statement... Your code should look like a variation of this:

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

#5

same error - "Oops, try again. Did you create a function called rental_car_cost?" I don't get it, I have defined the function :expressionless:


#6

refresh, try again. try a new browser maybe?


#7

Yeah . tried Edge didn't work there , Tried refresh ... same .


#8

Aha! On line 15, you need to make sure that rental_car_cost is NOT inside of plane_ride_cost. Only the function start is indented, so leave the rest alone. :slight_smile:


#9

You made my life so much easier :smile: Ty


#10

No problem! Glad you got it figured out!


#11

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