Taking a vacation rental_car_cost help!


#1

Afternoon Ladies and Gents! I am in need of service,so I was doing rental car cost on the lesson
and it took me a while to figure out how the code would work. Then it hit me but I am not receiving any
output in the console. This is the line of code I put in:

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

#2

I thought You need to use a second variable to calculate it and so I used total and now it won't show up anything(not like it ever did).


#3

You don't call and print your function.

For example add:

print rental_car_cost(4)

#4

Remove that line and return only the total as you have.


#5

couldn't you just put the argument and then put in parenthesis the number


#6

I tried that but it just pops up 2 None words into the console it may not be calling it or maybe there is something else wrong with the coding?


#7

Although I already tried that and it said that i can put an 'int' into it which frustrated me.


#8

def rental_car_cost(days):
    total = 40 * days
    if days >= 7:
        total -= 50
        return days                         <- this
    elif days > 3:
        total -= 20
    return total                            <- the return we want

What we want the function to do is calculate the total cost of renting a car for an x amount of days.
So it should always return the total.
But in your if-statement you suddenly return the number of days that were put in, but that's not what we want.
You don't have to return anything in your if-statement, because the variable total is returned after the if-statement, whether it returns true, or false.


#9

Ok so I removed the return days and tried just the returned total and it still won't come up


#10

Could you paste the code here again?


#11

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

#12

Wait ok it says that it shows 120 instead of 100 for 3 days I think the code is either factoring to much
or it maybe using both at the same time when it runs through, highly unlikey but a slight chance


#13

I got it so the answer to days(3) in this case * 40 equal 120. So that means it doesn't factor in the discounts.


#14

Yes it does.
Try changing the elif days > 3: operator to >=.


#15

I fixed it. the reason was is because of what you said the >= I totally forgot abut that
Thanks dutchc0de!


#16

You're welcome! Small errors are always hard to find.