Taking a vacation returns incorrect value though all syntax seems functional


Hi everyone I'm having some trouble understanding where I went wrong with this one. I've noticed that other people with a similar issue wrote their codes differently though I feel like this code makes sense to me. Heres my code:

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):
cost = 40 * days
if days < 7:
return cost
if days >= 7:
return cost - 50
elif days >= 3:
return cost - 20

The error message I receive is that rental_car_cost returns 120 instead of 100 for 3 days. I don't understand why it would return the incorrect cost for 3 days but not for >7 days. Thanks for considering my problem


I think you wanted to type:

if days > 7:

If you ask for days < 7, it will always take that route first


I don't think you need that first condition at all, you only need to see if days>=7 or days>=3. You do need to count for the case where days is 1 or 2, so consider changing what you have in that function to:

cost = 40 * days
if days >= 7:
   cost -= 50
elif days >= 3:
   cost -= 20
return cost