"Transportation"


#1


https://www.codecademy.com/courses/python-beginner-P5YtY/1/3?curriculum_id=4f89dab3d788890003000096


def hotel_cost(nights):
    return 140 * nights
def plane_ride_cost(city):
    if city == "Charlotte": # if the city is "Charlotte"
        return 183 # return 183
    if city == "Tampa": # if the city is "Tampa"
        return 220 # return 220
    if city == "Pittsburgh": # if the city is "Pittsburgh"
       return 222 # return 222
    if city == "Los Angeles": # if the city is "Los Angeles"
       return 475 # return 475
def rental_car_cost(days):
    return 40 * days 
    if cost >= 7:
        return -50
    elif cost >=3:
        total -20
    return cost


#2
 Line 13 of my code brings up at syntactical error.  Please advise.

Thanks!

Ian Michael Jones


#3
 Here is my corrected code that still doesn't run correctly.  Please advise.

Thanks!

Ian Michael Jones


#4

ef hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == "Charlotte": # if the city is "Charlotte"
return 183 # return 183
if city == "Tampa": # if the city is "Tampa"
return 220 # return 220
if city == "Pittsburgh": # if the city is "Pittsburgh"
return 222 # return 222
if city == "Los Angeles": # if the city is "Los Angeles"
return 475 # return 475
def rental_car_cost(days):
return 40 * days
if cost >= 7:
return -50
elif cost >= 3:
total -20
return cost


#5

def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == "Charlotte": # if the city is "Charlotte"
return 183 # return 183
if city == "Tampa": # if the city is "Tampa"
return 220 # return 220
if city == "Pittsburgh": # if the city is "Pittsburgh"
return 222 # return 222
if city == "Los Angeles": # if the city is "Los Angeles"
return 475 # return 475
def rental_car_cost(days):
return 40 * days
if cost >= 7:
return -50
elif cost >= 3:
total -20
return cost


#6

HI this function

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

to your if and elif statement you should change cost by days then in the returns statement
first this line

return 40 * days

instead of return you should save it in a variable (rent) so that when your days will be for example 3 you will remove the 20 to that variable (rent) so the if statement will be like that

def rental_car_cost(days):
    rent = 40 * days 
    if days >= 7:
       return rent - 50
......

#7
 Here is my code that still doesn't run correctly.:

def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == "Charlotte": # if the city is "Charlotte"
return 183 # return 183
if city == "Tampa": # if the city is "Tampa"
return 220 # return 220
if city == "Pittsburgh": # if the city is "Pittsburgh"
return 222 # return 222
if city == "Los Angeles": # if the city is "Los Angeles"
return 475 # return 475
def rental_car_cost(days):
rent = 40 * days
if cost >= 7:
return rent - 50
def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == "Charlotte": # if the city is "Charlotte"
return 183 # return 183
if city == "Tampa": # if the city is "Tampa"
return 220 # return 220
if city == "Pittsburgh": # if the city is "Pittsburgh"
return 222 # return 222
if city == "Los Angeles": # if the city is "Los Angeles"
return 475 # return 475
def rental_car_cost(days):
return 40 * days
if cost >= 7:
return rent - 50
elif cost >= 3:
total - 20
return cost

 Please advise.

Thanks!

Ian Michael Jones


#8

you didn't change this line

return 40 * days

like I said then this line

total - 20

you didn't define a variable total

you should save 40 * days in a variable for example rent then in your if and elif statement remove first 50 in the if statement then in the elif statement 50 to rent


#9
 Here is my new code after making your few suggestions; however, it still doesn't run correctly.:

def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == "Charlotte": # if the city is "Charlotte"
return 183 # return 183
if city == "Tampa": # if the city is "Tampa"
return 220 # return 220
if city == "Pittsburgh": # if the city is "Pittsburgh"
return 222 # return 222
if city == "Los Angeles": # if the city is "Los Angeles"
return 475 # return 475
def rental_car_cost(days):
rent = 40 * days
if cost >= 7:
return rent - 50
elif cost >= 3:
rent - 20
return cost

 Please advise.

Thanks!

Ian Michael Jones


#10
 I also receive the following error.  "Oops, try again. An error was raised for rental_car_cost(1): global name 'cost' is not defined."

#11

Here

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

should be

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

Like you can see in the if and elif condition you should put days since it's the argument of the function and in the elif statement you just need to add return then the last return statement should return rent.


#12
 After doing what you said, my code ran correctly.  Thanks for all of your help.

Sincerely,

Ian Michael Jones


#13

Or, you could run code, like in their example:
def rental_car_cost(days):
cost = 40 * days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost


#14

Givit a try for me it worked

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