Transportation


#1

Why is my code not working?
def rental_car_cost(days):
cost = 40 * days
if days >= 7:
cost -= 50
elif days >= 3 and days < 7:
cost -= 20
return cost


#2

Hmm..it should work.
Is your code indented like this?:

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

#3

Yeah, it is indented.


#4

The error is return is none


#5

That is not an error. It's correct. return doesn't always display things in the console. If you want to show something in the console, use print such as print rental_car_cost(40).

But remember, print is not the same as return.


#6

Nah, it is an error, because it will not let me continue on to the next lesson. Typing in print rental_car_cost(40) prints none in the console as well.


#7

Do you get an error message? What does it say? Also, please provide the rest of the code as the error doesn't come from the one you provided and you said you indented properly (because I've used your code with mine in the same lesson and it passed).


#8

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 "You have entered an wrong destination"
def rental_car_cost(days):
cost = 40 * days
if days >= 7:
cost -= 50
elif days >= 3 and days < 7:
cost -= 20
return cost


#9

that's all indented properly


#10

This is the error:
Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days.


#11

That is really strange. It should work. I put your code into my lesson and it passed.

Perhaps try using a different browser or refreshing.


#12

@leonhertz ,

If your code is indented like this ...

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

... then it is incorrect, and will return None whenever days is less than 3 or when it is 7 or greater.

The issue may be the degree to which this line is indented ...

return cost

#13

Yup, that was it thank you.


#14

A post was split to a new topic: Transportation


#15