Please help me to correct my code


#1



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


It is throwing error message Oops, try again. It looks like rental_car_cost returns 96.0 instead of the correct amount (100) for 3 days.


Correct amount of rental car should display


Replace this line with your code.


#2

How do we help you without your code?

the exercise url is the same for everyone, please copy paste your full code to the forum

also, use markup:

so your indention will show


#3

Instructions
Below your existing code, define a function called rental_car_cost with an
argument called days.
Calculate the cost of renting the car:
Every day you rent the car costs $40.
if you rent the car for 7 or more days, you get $50 off your total.
Alternatively (elif), if you rent the car for 3 or more days, you get $20
off your total.
You cannot get both of the above discounts.
Return that cost.
'

Code :

def rental_car_cost(days):
    cost=40
    rate=cost*days
    if days >= 7:
        total=rate-0.5*rate
        return total
    elif days >=3:
        total=rate-0.2*rate
        return total
    else :
        return rate

rental_car_cost(2)

#4

why such complicated math? in your if statement, just subtract 50, in your elif statement, just subtract 20


#5

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