Help Please!


#1

Hi Everyone,
would you help me on this case, please?:
THANK YOU!
It shows an error after running ... and says :"Oops, try again. It looks like rental_car_cost returns 96.0 instead of the correct amount (100) for 3 days."
:airplane: :blush:
def hotel_cost(nights):
return 140*nights
def plane_ride_cost(city):
if city=="Charlotte":
return 183
elif city=="Tampa":
return 220
elif city=="Pittsburgh":
return 222
elif city=="Los Angeles":
return 475
def rental_car_cost(days):
cost= 40*days
if days >= 7:
cost = cost - 0.5*cost
elif days >= 3:
cost = cost - 0.2*cost
return cost


#2

Might wanna get the formatting right for your code so we can read it.

When you see that error message, do you agree with it? What should the result be for 3 days? Which actions need to be applied to the number three to reach that result? Which actions do you apply in your function?


#3

Thank you so much for your time and comment,
actually these are the steps I followed:
=============================
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.
=====================

I don't know why it still doesn't work!


#4

Which part of your code takes 50 off the price?
And 20?


#5

It's here:
def rental_car_cost(days):
if days >= 7:
cost = cost - 0.5*cost
elif days >= 3:
cost = cost - 0.2*cost
return cost


#6

Sure. But where exactly do you take off 50? It would involve the number 50, right?


#7

It's here:
[corrected]

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


#8

As an aside, you still have to format your code correctly if you want others to make any sense of it! Can you tell that the code in your post isn't valid when it's missing its indentation?

Details matter a lot in programming, because computers do exactly as told. So it's important to make sure that those details show up in your post.

Next time you post some code, check out the buttons in the post editor, one of them is preserving the format of preformatted text, such as code.


#9
def rental_car_cost(days):
    cost= 40*days
    if days >= 7:
        cost = cost - 0.5*cost
    elif days >= 3:
        cost = cost - 0.2*cost
    return cost

=====================
Thank you dear @ionatan for your nice comment, the code doesn't induce an indentation error, the problem is that I think my code should work but "codeacademy" doesn't agree with me!


#10

It may not, but we have to be talking about the same code, right! And indentation isn't just valid or not, it carries meaning, otherwise it wouldn't matter and there wouldn't be any invalid indentation either.

So do you agree that for 3 days, there should be a discount of 20?
So 40 per day with a discount of 20 is 100, just as the error message says.

Call your function and see what happens. The error message already does this, but hey, if you don't believe it.

Or if you think it should behave in some other way, you'll have to explain that you disagree with the error message!


#11

Here's some reading, it's a bit on the long side, but it's really important!
http://www.catb.org/esr/faqs/smart-questions.html

..I really should post that link more often.


#12

Oh I didn't notice that it asked "$20" and not"%20" ... sorry ...
I appreciate your time dear @ionatan , thank you for sending the link!
Happy New Year!
Sincerely,
Soheil
============


#13

Sure, that was silly, but I think we might have gotten somewhere with your troubleshooting skills which is worth so much more.