Whats the error in the code? gives Invalid output to all input cities


#1
night=input("number of nights")


city=raw_input("Name of `Preformatted text` city")


def hotel_cost(night):
  total=140*night
  
  return total


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"INVALID INPUT"
  
  
  
  
print hotel_cost(night)
print plane_ride_cost("city")
  

#2

here:

print plane_ride_cost("city")

you pass a string city, if you want to pass the input of the user, you need to pass the variable city as argument to function call


#3

Still shows invalid input for all cities


city=raw_input("enter city")

days=input("number of days")


def hotel_cost(night):
  total=140*night
  
  return total


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"INVALID INPUT"
  
cost=days*40
  
  
def rental_car_cost(days):
 global cost
 if days>=7:
    cost-=40
    return cost
  
 elif days>=3 and days<7:
    cost-=20
    return cost
 else:
    return "INVALID INPUT"
  
  
  
  
print hotel_cost(night)
print plane_ride_cost("city")    #should take input
print rental_car_cost(days)
  
    
  	

#4

well here, as @stetim94 said, you still have "city" instead of city which indeed would pass invalid input each time.


#5

Thanks got it …appreciate your help


#6

I only showed the line where you did it wrong, it wasn’t the solution. The solution had to come from you, you would have learned more this way. My next hint would indeed have been:


def plane_ride_cost(city):
    print city
    # rest of code

print plane_ride_cost("city") 

see that you pass wrong argument at function call

but nickgrimes already got you to the solution


#7

Thank you very much…

I ahve coorrected the code but it still shows unsupported operand error …

please could you help me



city=raw_input("enter city")

days=input("number of days")

night=days-1

spending_cost=input("enter additional costs")

def hotel_cost(night):
  total=140*night
  
  return total


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"INVALID INPUT"
  

  
def rental_car_cost(days):
  
  
 cost=days*40

 if days>=7:                  
   cost-=50
   return cost
 elif days>=3 and days<7:
    cost-=20
    return cost
 else:
   return cost
  
  
def trip_cost(days,city,spending_money):
  sum= rental_car_cost(days)+ hotel_cost(days-1)+plane_ride_cost(city)+spending_money
  return sum
  
  
  
print hotel_cost(night)  
print plane_ride_cost(city)   
print rental_car_cost(days)
print trip_cost(city,days,spending_cost)
  
    ```


the error

enter cityTampa
number of days12
enter additional costs12
1540
220
430
Traceback (most recent call last):
File “python”, line 57, in
File “python”, line 49, in trip_cost
File “python”, line 39, in rental_car_cost
TypeError: unsupported operand type(s) for -=: ‘unicode’ and ‘int’


#8

#9

New problem, you made a new topic. I will help you there, this topic has been resolved