Transport


#1

Hey Fellows of computation!
I'm struggling in trying to discover how is supposed to write the code in this part

https://www.codecademy.com/courses/python-beginner-pt-BR-f2til/1/3?curriculum_id=53594ed4fed2a85327000001

I'm definitively stuck here. Can someone help me? I don't know how to put the discout and how to return the cost. It is quite confusing because the instructions don't give precise orientation on what we are suppose to put in the lines. It says there are indentation erros and that the code is weird.


Replace this line with your code.


#2

The second from bottom line: rental_car_cost = 20 that should be indented two levels, to sit under: elif days >-3.


#3

It did'nt work. Also, there are not only indentation errors. But thanks


#4

On line 13:

rental_car_cost(1) = 40

You can't assign to a function call. That will throw an error.

Every day you rent the car, the car will cost you 40.

So basically, you will need to write a math equation.


#5

Ok, lets look at your discount function:

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

A number of this going wrong here:
1) What @intermediategamer said above. Also, when you do rental_car_cost - x, you are trying to take x away from a function object, not it's eturned value. And you return rental_car_cost(), but cost should take one argument so you will get an error there.

2) Lets look at what is happening with you if statements. First you are saying if it is over or equal 7 days make this discount x. However, if that if statement is True then elif days >=3 will be True too and so you will get the discount for 3 or more days but less than 7 applied.

When doing if statements you can chain the logic, i.e.:

if a <= b < c:

Next you want your function to end and return the discount when one of your if statements are True. So you use return under the if statement to send back the desired discount.

So your logic is going to look something like this:

def rental_car_cost(days):
    baseCost = #work out cost before discount
    if days >= 7:
        # Minus  discount from baseCost and return it
    elif days # 3 or more and less than 7:
          # Minus discount from baseCost and return it
    return # No discounts apply so just return the cost

#6

I tried this way. but it generates the following error message: Oops, try again. An error was generated for rental_car_cost(1): maximum recursion depth exceeded


#7

cost = days * 40

why create a variable called cost? You should assign it to the function name because that's where your information will go back to.

return cost - 50 #and the other returns in your statements

Like i said above:

You should assign it to the function name because that's where your information will go back to.

elif 3 <= days < 7:

Did you read this part in the instructions?:

If you rent the car for 3 or more days...

This isn't needed: < 7. Currently, you're checking if 3 <= days (3 is less or equal to days). You need to check if 3 is the opposite of that.

(Hint: what's the opposite of less?)

Lastly:

return rental_call_cost(1)

Ints aren't callable. You just need to return it back to the function name, not the input.


#8

Sorry, i'm completely new into this programming thing. I did some changes: I atributted the number of days assigning it to the function, removed the integers, and put another elif statement (as the instructions recommend). But it says there an error: File "python", line 14 SyntaxError: 'return' outside function.


#9

No need for that last elif statement.
See the error? return outside function? It's telling you that because your code isn't indented.

if rental_car_cost >= 7:

Did you see what I quoted earlier?

If you rent the car for 3 or more days...

Here they ask you to compare the days, not the function.

Example:

if days #is greater or equal than... etc.

Also, no need for parentheses after returning, that will throw an error.


#10

Its says the 14 line is outside function, but i tried many times to correctly indent this line but it doesn't work. I hope everything else is alright...I took out the additional elif, i replaced the function with 'days' and removed the parenthesis.


#11

In your previous screenshot, the return keywords in your if/elif statements were just fine, you just needed to remove the parentheses.

Example:

return rental_car_cost - #etc...

Like I've said, don't forget to indent your code.

And no need for the last return statement (line 17).

If you're having more trouble, study the error messages on the console, (it helps a lot when trying to find an error), or look back at the previous lessons if you need​ to review something.

Here's some links that may help:

https://www.codecademy.com/en/forum_questions/5592f9f49113cb25af0000fe

https://www.codecademy.com/en/forum_questions/51c0e35d7c82caace80008b1


#12

Thank you intermediategamer


#13

Sure, no problem. :slight_smile:


#14

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