Taking a Vacation - 4. Transportation [Help]


#1

Hello, I'm having some problems with my code, can some one help me?

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

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


#2

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

I am receiving the same error message for my code as well.


#3

I figured it out:

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


#4

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


#5

hello,
the previous functions work ok am now at the whole trip cost and the console does not want to print, I have the following

def trip_cost(city,days,spending_money):
return rental_car_cost(days)+plane_ride_cost(city)+spending_money
print trip_cost("Los Angeles", 5, 6020)


#6

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

This should work. It is the same as @gigaplayer53733's, but I eliminated the first 'return total'.


#7

Im having trouble with this too. I've inputted the code as it looks below but I'm getting the error message "Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days." I've tried refreshing the page and resubmitting and still get the same thing.

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


#8

So I am inputting this:
def rental_car_cost(days):
cost = days * 40
if days >= 7:
cost == cost - 50
return cost
elif days >= 3:
cost == - 20
return cost

and the output I am receiving is the error message saying:
Oops, try again. It looks like rental_car_cost returns 120 instead of the correct amount (100) for 3 days.

Anyone have any ideas?


#9

I got mine to work when I just did
total -=50 instead of total = - 50


#10

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

please help! error message is: 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: expected an indented block (python, line 16)
and line 16 is total= days *40


#11

I finally figured it out.
def hotel_cost(nights):
return hotel_cost(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):
total =( days*40)
if days >= 7:
return total-50 // I initially wrote total= total - 50 and it wouldn't work.
elif days >= 3 and days < 7:
return total-20
else:
return total


#12

yeah I'm still having trouble with mine. Here is my code :

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

thanks!


#13

it comes out -10 when they set days to equal 1, so I guess the first conditional for the 7 day discount is returning true when is should return false


#14

CORRECT CODE IS :slightly_smiling:

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


#15

weird... thats not working for me

do you mean def instead of if on the first line? That doesn't work either.

I'm calling the conditional myself, setting my own arguments, to narrow down the problem, and I really think its that first conditional. But the code looks a lot like everyone else's, except for the name of the variable for cost per days, but that shouldn't affect anything, right?

I've been messing with it, and it seems i can only get one conditional to work at a time, and seems to depend on this line:

elif cost >= 3

OR

elif cost >= 3 and cost < 7


#16

PROBLEM SOLVED :joy:
it should be if DAYS >= 3 , not cost *facepalm

here is my completed code:

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


#17

def rental_car_cost(days):
rental = (40 * days)

if days >= 7:
    rental -= 50
elif days >= 3:
    rental -=20
return rental

You just need the function(mine was rental) that equals 40 * days to be subtracted from and then returned.


#18

So I've changed my code to what you see below...

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

...and now it's telling me "Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (100) for 3 days." This is driving me insane.


#19

Hi here

elif days>=3 and days<7:

Can you try to remove this part and days<7


#20

Tried removing that part and I'm STILL getting the same error message. So weird.