Did you create a function called rental_car_cost?


#1

I've copied and pasted 7 different versions of people saying they got their code to work and none worked. What was your code? Mine is saying right now Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days.


4/7 Transportation
#2

@alisoncarey: Just take a look at what @gaurangtandon said on his post and you should get your code working.


#3

https://www.codecademy.com/courses/python-beginner-P5YtY/1/3?curriculum_id=4f89dab3d788890003000096#

Thanks, I've tried a 8th version, can you let me know where I am going wrong?


#4

@alisoncarey: Mind telling what's the error and posting your code, please?


#5

I posted link above: https://www.codecademy.com/courses/python-beginner-P5YtY/1/3?curriculum_id=4f89dab3d788890003000096#

Error: Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days.

Copy and Paste code:

{def rentalcarcost(days):
cost = days * 40

if days >= 7:
    cost -= 50
    
elif days >= 3:
    cost -= 20 

return cost

#6

The "{" symbol was pasted there, but is not included in the code. I thought you had to use that to post code in the correct format.


#7

@alisoncarey: I've tested your code and it prints the correct output for an input of 40 days.
Try testing it on repl.it and see if you got the same error, if not, refresh the page or try a different browser.

Note: make sure you are following the instructions that were given to you in that lesson. Not following them sure won't let you pass.


#8

@g4be what is repl.it?


#9

@alisoncarey: Some sort of compiler, here it is


#10

@g4be I used IE and got same error. I had previously been using Chrome.


#11

@g4be I just tried your compiler and pressed "run" and it returns "none"


#12

https://www.codecademy.com/courses/python-beginner-P5YtY/1/3?curriculum_id=4f89dab3d788890003000096

New error message when using IE.

Error: Oops, try again. Did you create a function called rental_car_cost?

Code:

def rentalcarcost(days):
    cost = days * 40

    if days >= 7:
        cost -= 50
    
    elif days >= 3:
        cost -= 20 

    return cost

#13

Okay, @g4be the code worked. I had to change to put "_" in the def name.