Transportation syntax error outside function PLEASE HELP


#1

def rental_car_cost(days):
cost = days*40

if days >=7 :
cost -50

elif days >=3:
cost -20
return cost
////////////////////

it says syntaxerror: 'return' outside function and i cant seem to fix it


Replace this line with your code.


#2

Use return in front of cost.
Ex.

if days >= 7:
return cost-50


#3

This is the correct code.

def hotel_cost(nights):
return nights * 140

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:
return False

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

hope this help!


#4

Is there any need for the variable rent?

I just did this:

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

It passed the lesson but I always come here and check how others did it and everyone seems to be using a variable, so I'm wondering why


#5

Yes, the rent variable is there so that the computer can calculate the rental_car_cost. At least that what i think :confused:


#6

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