Getting unexpected indent error, what i did wrong?


#1

Preformatted text


File "python", line 14
if days>=7:
^
IndentationError: unexpected indent


def hotel_cost(nights):
    return 40 * 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:
       return total - 50
    elif days>=3 and days < 7:
       return total-20
    else:
        return total
def trip_cost(city, days, spending_money):     
    return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
    print trip_cost("Los Angeles", 5, 600)


#2

this two lines:

   total = 40 * days
    if days>=7:

the indent levels don't match


#3

even after giving space its not working,how to fix this?


#4

can i see an updated version of your code + error message?


#5

def hotel_cost(nights):
    return 40 * 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:
       return total - 50
     elif days>=3 and days < 7:
       return total-20
     else:
        return total
def trip_cost(city, days, spending_money):     
    return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
    print trip_cost("Los Angeles", 5, 600)

#6

Error message is same!!


#7

indention refers to the white spacing:

   total = 40 * days
    if days>=7:

if has one more space, so you should give total one more space as well:

    total = 40 * days
    if days>=7:

#8

now i getting

Oops, try again.
hotel_cost(1) returned 40 instead of the correct value 140

def hotel_cost(nights):
    return 40 * 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:
       return total - 50
    elif days>=3 and days < 7:
       return total-20
    else:
        return total
def trip_cost(city, days, spending_money):     
    return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
    print trip_cost("Los Angeles", 5, 600)

#9

from exercise 2. where you build the hotel cost function:

The hotel costs $140 per night. So, the function hotel_cost should return 140 * nights

i helped with the issue you have been stuck on for a while. Please see what you can find out if new errors arise, if you can't figure it out after a while, you can always post on the forum


#10

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