4/7 Transportation


#1


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)


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


#2

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


#3

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


#4

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.


#5

You should be likle that

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

and

return cost -= 20

#6

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


#7

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


#8

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 rentalcar_cost returns None instead of the correct amount (100) for 3 days._

I am confused, what am I missing?


#9

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


#10

İ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:


#11

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)


#12

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


#13

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


#14

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


#15

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.


#16

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.


#17

thank you. I got it.


#18

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


#19

guys the problem has been solved in post 6


#20

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