4/7 Transportation

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Your code threw the following error: unexpected indent (python, line 14)

<What do you expect to happen instead?>

```python

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

<do not remove the three backticks above>

your if statement needs to be at same indent as variable cost

Hi first you don’t need of the $ before the number then before the -= its missing cost

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

Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Your code threw the following error: invalid syntax (python, line 15)
Its also saying to remove the = sign

File “python”, line 15
return -=50
^
SyntaxError: invalid syntax

i did that and this comes up:

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

Oops, try again. It looks like rental_car_cost returns -20 instead of the correct amount (100) for 3 days.

You should be likle that

return cost -= 50
or
return cost = cost - 50

and

return cost -= 20

that wouldnd work for me but cost - 50 worked!

thx

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

1 Like

This one worked for me:

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

I wrote this

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

But I get "Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (100) for 3 days.

I am confused, what am I missing?

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

İn this case, if the day between 3 and 7 the both process will be done. ( I mean the cost will be - 20 and - 50 at the same time). To prevent this, I wrote elif days >= 3 and days < 7:

I am having a similar problem, can anyone help please?

def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
city= input('Enter your name: ')
if city==“Charlotte”:
return 183
elif city==“Tampa”:
return 220
elif city==“Pittsburg”:
return 222
elif city==“Los Angeles”:
return 475
def rental_car_cost(days):
if days <= 2:
return days * 40
elif days > 2 and days < 7:
return days * 40 - 20
else:
return days * 40 -50
def trip_cost(city,days,nights):
return plane_ride_cost(city) + hotel_cost(days) + rental_car_cost(days)

in that case if days = 10 will won`t work!!

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

lo resuelves asi

I’ve tried this code a few different times

def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == “Charlotte”:
return 183
if city == “Tampa”:
return 220
if city == “Pittsburgh”:
return 222
if city == “Los Angeles”:
return 475
def rental_car_cost(days):
return days * 40
if days >= 7:
return rental_car_cost - 50
elif days >= 3:
return rental_car_cost - 20
else:
return rental_car_cost

and i keep getting

Oops, try again. It looks like rental_car_cost returns 120 instead of the correct amount (100) for 3 days.

Anyone have any suggestions? Please explain too, still getting the grasp of this

OK so I changed it to

def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == “Charlotte”:
return 183
if city == “Tampa”:
return 220
if city == “Pittsburgh”:
return 222
if city == “Los Angeles”:
return 475
def rental_car_cost(days):
car_cost = days * 40
if days >= 7:
return car_cost - 50
elif days >= 3 and days <= 6:
return car_cost - 20
return car_cost

And this seems to work. From what I can tell, I needed to define a separate variable for the actual cost, and use that

I have this one worked: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 = days * 40
if days >= 7:
return cost - 50
elif days >= 3 and days < 7:
return cost -20
else:
return cost

but why not working like the example?

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

    return cost

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

1 Like

Hi its maybe because of the indent so if you it to work it should be like that

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

and the space between - and = here

cost - =50

you should remove it.

2 Likes

thank you. I got it.

1 Like

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

guys the problem has been solved in post 6

this is the correct code:

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