Lets take a vacation: your


#1

I keep getting the error: "It looks like rental_car_cost returns 120 instead of the correct amount (100) for 3 days."

Apologises for the indentation, unsure how to fix :confused:

My code:

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
else:
print 'city is not in the code'

def rental_car_cost(days):
return 40 * days
if days >= 7:
(40 * days) - 50
return cost
elif days >= 3:
(40 * days) - 30
return cost
else:
print "no bonus discount for you!"


#2

a function ends the moment a return keyword is reached, in your case here:

return 40 * days

the first line of the function. You might want to change this. Take a moment to look at your code again if new errors arise, if after a while you still need help post an updated version of your code with format:


#3

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
    else:
        print 'city is not in the code'
        
def rental_car_cost(days):
    cost = 40 * days
    if days >= 7:
        cost = (40*days) - 50
        return cost
    elif days >= 3:
        cost = (40*days) - 20
        return cost
    else:
        print "no bonus discount for you!"

#4

Uhm.. no? Your function should reach a return keyword, that now only happens when the days are between 3 and 7.

Also, these lines:

(40 * days) - 50

don't do much, look at the following example:

i = 5
print i // 5
i + 5
print i // 5
print i + 5 // 10
print i // 5
i = i + 5
print i // 10

you do have to update a variable (or create one, whatever you like), even if there is no discount you should still return cost, in all cases a return keyword should be reached (or you just update cost with the necessary discount and then at the end return total)

I corrected your markup (which was wrong), now you changed it back, it is still wrong


#5

Sorry I edited the code again

edit: Ah I got it now! Thank you. I've had this issue before but I recognised it.

For anyone who struggled and looks through past posts, here is my edited code now working:

...

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
else:
print 'city is not in the code'

def rental_car_cost(days):
cost = 40 * days
if days >= 7:
cost = (40*days) - 50
elif days >= 3:
cost = (40*days) - 20
return cost
else:
print "no bonus discount for you!"
...


#6

the indent of your return is not correct, it should reach that line in all cases, not only if elif runs. Your markup still requires some work, you don't use backticks, you use quotation marks


#7

I don't understand, sorry my english isnt the best, can you show me please?


#8

if condition:
  print "do something"
elif condition:
  prnit "do something"
  return "now return keyword would only be reached if elif is true"
return "return keyword is reached in all cases"

#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.