5/7 yet again


#1

getting a strange error and just cannot understand why

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


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


def trip_cost(days, city):
    hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)
        return trip_cost()

error - File "python", line 27
return trip_cost()
^
IndentationError: unexpected indent


#2

Error is here

the returrn here

has the wrong indentation. push it 4 spaces back(or 1 tab)
also
the aim is to return this line

not this


#3

so i changed it to

def trip_cost(days, city):
        hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)
        return trip_cost(days,city)

now i get

Oops, try again. trip_cost('Pittsburgh', 5) raised an error: global name 'nights' is not defined

i just cannot understand it


#4

What i meant was write return

night is not defined anywhere in your function perhaps you wanna write days


#5

thnx alot for helping m8, i reworked my code completely and passed, but i just cant get it where i was wrong to me it seems like mostly nothing changed except for total added

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


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


def trip_cost(city, days):
    return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)

#6

forgot to make my post a reply to yours, cheers


#7

@bitace30390 the is good that you have been able to solve it .
initially you had indentation issues(remember python is very strict on indents) and you were returning the wrong thing


#8

yeap i understood the returning part, but the second one worked ok @ IDE, seems like there are strict rules throughtout the course itself


#9

read this thread carefully as I was getting a mistake: invalid syntax and still didn't get what went wrong. At a closer look I discovered that I had missed one underscore. As Yogi Berra put it: "A lot of problems can be solved just by looking" :grin:


#10

def hotel_cost(nights):
cost_nights = nights * 140
return cost_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 :
    return "none"

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

def trip_cost(city, days):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)

help me too :frowning: