Taking a vacation (Code arragement problem?)


#1

Hello guys, im trying to learn Python and the tutorials in this page are really helping me, however im having problems with how to write the code. In the exercice Taking a vacation i got a weird error:

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

This code is the answer to the exercie, and mine had just 1 minor difference, the last line "return cost" was 1 space to the right and this was giving me an error.

My question is: Is this sort of code arrangement error very common on python? or is it just a thing with how the exercices in codecademy are programed?

I'd really like to know because i got stuck on this exercise trying a bunch of different ways to make it work and none of them were correct and i wanted to know if my logic to program is failin me or the way the tutorials are programed. (sorry for my bad english)


#2

If you added one space at the front of the last line it would no longer be valid python code.
(ignoring the extra asterisks in the parameter list)

Run the code locally if unsure, use python2 if you're comparing as there are some minor differences in python3

Syntax errors, including indentation, are generally trivial to fix. Choosing indentation level for a line is just about matching it to the suite that it is supposed to belong to.

If you find yourself having trouble with syntax then you'll just have to go look up the syntax for what you're doing. You can also save yourself some time by not guessing when you're not sure and instead just looking it up.


#3

Thank you for the response ionatan. The extra ** are because i wanted to remark in black some letters, but yeah, thats on my.

I guess i'll have to get used to how python code is writen.


#4

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