Pull it together


#1

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

Indentation driving me nuts. I have tried using just spaces then tabbing. Both brought up error message as follows:

File "python", line 16
if days >=7:
^
IndentationError: unindent does not match any outer indentation level

Can someone explain where I am going wrong as pulling my hair out rather than pulling it together:>p Thanks


#2

The above doesnt show the indentation I actually used grr. This is one of those so obvious answers that I cannot see it arrgh. I have lazy eyeballs!!


#3

Hello, @pymaster23365!
According to the error message, the only thing wrong is the indentation.
Also:

elif days <7 and >=3:
cost = cost - 20

Is also wrong because you're comparing the value with nothing.

It seems that fixing those errors, might make your code work correctly.


#4

Hi,
I am having trouble with this code too. Mine is as follows (hopefully indentation works):

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
else:
return()

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

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

// I am not getting an error in the console but this from codeacademy:'

Oops, try again. trip_cost('Charlotte', 1) raised an error: sum expected at most 2 arguments, got 3

Not sure what is wrong here?
Thanks


#5

Hey @mikepretty ,
there is a second commata for a third argument in the Function trip_cost, what happens if you delete it?

Greets


#6

hi,
The error is without this comma there. I had tried adding a 3rd argument to trip_cost before posting and accidentally left the comma there when copy/pasting code


#7

stuck, help please!
It keeps saying I have not defined trip_cost. I am pasting everything here. thanks in advance

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):
cost = 40 * days
if days >= 7:
return cost - 50
elif days >= 3:
return cost - 20
else:
return cost
def trip_cost(city,days):
return rental_car_cost(days) + hotel_cost(nights) + plane_ride_cost(city)
print trip_cost


#8

Hi inside hotel_cost(here) try to put days

#9

Doing this you'll simply get a message informing you where such function is in the memory, a.k.a. memory address.

In order to actually get the return value of it, you'll need to pass some arguments, since that function requires some of them.

print trip_cost('Los Angeles', 3) #Returns some value
print trip_cost #Prints where in the memory such function is located

#10

Looks like problem was indentation. re-entered the code and it worked.
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):
cost = 40 * days
if days >= 7:
return cost - 50
elif days >= 3:
return cost - 20
else:
return cost
def trip_cost(city,days):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)


#11

Hi g4be

Still getting this error. I have indented the code blocks using
two tabs for If and else
File "python", line 16
if days >=7 :
^
IndentationError: unindent does not match any outer indentation level


#12

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):
cost = 40 * days
if days >=7:
return cost -50
elif days >=3:
return cost -20
else:
return cost
def trip_cost(city,days):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)

Thanks used this and it worked. It was my indentation. I messed around with it a bit then it worked. Was a pain though. I need to get clear in my head the rules again on indentation and tabbing and spaces allowed not allowed duh. Also to be careful about making sure definition names are consistent... Cheers for help.


#13

@pymaster23365: Your if/elif/else statements, considering you're not using anything nested, should be at the same "indentation level" of your function's name.

def functionA():
    if "Test" == "Teste:
      print ("Is equal")

Edit: Glad you found and fixed it! :slightly_smiling:


#14

Hi G4be
Problem was I keep forgetting whether it is two tabs to get to the right position or spaces using the space bar. I know one approach is meant to be the preferred safer option doh. I need to just train myself to stick to the right approach. Knew it would be something dumb like this.
cheers for your help
D