Most likely a common mistake, please help?


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

The error returns:
Oops, try again. It looks like rental_car_cost returns -10 instead of the correct amount (40) for 1 days.

I feel as though this is a common mistake so if you recognise it, please halp...


#2

Hi you should make that cost - 50 = cost
Like that cost = cost - 50 same for the other.


#3

Sure thanks for the quick reply


#4

Exactly. The variable getting "filled" is on the left side of the equals sign. The right side of the equals sign is what the variable is filled by.


#5

Nope, sorry came up with "Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Your code threw the following error: can't assign to operator (python, line 7)"


#6

That's what you had before. You want, as @wizmarco said, cost = cost - 50. The same thing is true for this line, which also needs to be fixed: cost - 20 = cost should be cost = cost - 20.


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

Like this?


#8

Try it and see what happens. :wink:


#9

> Oops, try again. It looks like rental_car_cost returns -10 instead of the correct amount (40) for 1 days.
:disappointed:


#10

It's okay. You're getting closer. Two things to check:

  1. Do you want to return a value no matter what?
  2. Is the $50 discount supposed to be for seven or less days, or for seven or more days?

#11

Here the Right indent

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

#12

Okay so it's if the days are greater than 7 there is meant to be a discount of $50. I think everything is placed properly but it might be from the face that I didn't specify whether it's just simply over 3 days or between 3 and 7.


#13

Nope, still returns as error, but thanks


#14

In your else if statement make days >= 3 also in the if statement days >= 7


#15

What does your function return if days = 2?


#16

Oops, try again. It looks like rental_car_cost returns -10 instead of the correct amount (40) for 1 days.
(Sorry for long reply)


#17

Well that would mean if days is less than 7/3, and we want if it's greater than (<)


#18

No if days greater than 7 so Its like that days >= 7
Its like that .
Less than < greater than


#19

oh nevermind I just solved it :joy: all I needed was a separate variable for the two discounts, but thanks for the effort :+1: