Transportation issues


#1



Transportation


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


I have tried different solutions to this issue, but cant seem to get it working..


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


#2

back to instructions.

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.

and your if and elif conditions..

days <=7
days <=3

can you figure out the cause of the error?
do reply what you get after making some changes there! :slight_smile:


#3

Hiya @greentreemee :slight_smile:

Thank you for your speedy response...
I have changed the code to this now, which first didnt work...

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 = days * 40

if days <=7: 
    cost -= 50

elif days<=3:
    cost -= 20 

else: 
    return cost

but when I added

def hotel_cost(nights):
return 140 * nights

at the top it suddenly worked... could you explain to me why?

Thank you :slight_smile:


#4

@phdbean,
Are you sure that your current posted code is working or it worked after modification?


#5

Hi @greentreemee.

sorry for my late reply but I gave up yesterday...

Yes it seems really weird I have just tried again and deleted the first few lines and then it came up with an error saying invalid syntax for the "-=" in my code...


#6

Hi @phdbean,
Your code is fine except the two lines I mentioned earlier.

There are few things to revise..

Conditional operators (>, <, >= , <= ,>=, == ,!=) and using them to make Conditional expressions

When we say x is greater than y..
We write this x > y

When we say x is less than y..
We write this x < y

When we say x is greater than or equal to y..
We write this x >= y

When we say x is less than or equal to y..
We write this x <= y

when we check if two things are equal..we write this..
x == y

when we check if two things are not equal..
we write
x != y

So you can see how we translate our thoughts using programming.

Now back to instructions..

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 can see it says 7 or more days.
But inside your code,You mistakenly wrote this days <=7

It should be days >= 7.

same changes you have to make in this line of condition..

days <=3

I hope it helps.
If you still find it a bit complex,I'll explain!


#8

thank you for your help! :slight_smile:

this one has just been really weird..


#10