Need help, lesson 4


#1

I've tested, tested, and retested this and I cant figure it out.

The lesson is saying rental_car_cost(3) is returning 120, but when I run it in actual Python, it returns 100, and I can't find out what's wrong with the code so I can't move forward in the lesson.


#2

Pretty sure that does not return 100 anywhere for 3 days.

But then again that code will not run at all, make sure the code in your post is intact.


#3

wrong test code....sorry


#4

ok, don't know how to show the indents in the forum, but I know they are right in my code


#5

Maybe you just think they are. There's something wrong with your code and you don't know what it is right. Either way, it's a hindrance if they aren't there and it's much easier to get help if your post looks good. More fun for those giving their time too.

There are some buttons in the editor where you enter your post!


#6

That's EXACTLY what I have, and my tests say its ok


#7

This is how you indent.

4 for if/elif/else statements. Example:

    if

8 for the stuff inside the ifelif statements

        return True

basically you go up by for as you go inside your code


#8

I don't understand, what do you mean? I type numbers and only get numbers


#9

Indent everything by another 4 spaces in your post. Or highlight it and press the right button. Or put three backticks before and after the code.

You also said that your function returns 100 in your test. It does not.

Try reading your code from the top for 3 days. What will it return?

It will return 100.0 for 2.5 days, that's not quite right though.


#10

line 2:
cost = days * 40
cost = 3 * 40
cost = 120
line 8

cost = cost - 20
cost = 120 - 20
cost = 100

im not trying to be difficult, and thanks for explaining the indenting, but the way I see it, the code is still good
where am I going wrong?


#11

this went through, what changed?
def rental_car_cost(day):

cost = day * 40
if day >= 7:
    cost = cost - 50
    return cost
elif day >= 3:
    cost = (40 *  day) - 20
    return cost
elif day < 3:
    cost = day * 40
    return cost

#12

In your original code you need to change cost = cost - 50 and cost = cost - 20 TO cost -= 50 and cost -= 20


#13

You also only need return cost at the end of your code. It's not needed for all three if statements


#14

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