Can You pick out the fault in this code?


#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):
cost=40*days
if days >=7:
cost -=50
elif days>=3 and days<7:
cost -=20
return cost
def trip_cost(city,days,spending_money):
return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days) + spending_money
n = input("Please Enter the city where you gonna go:")
l = input("Please Enter the number of days:")
m = input("Please enter the extra spending money:")
travelling = trip_cost(n,l,m)
print (travelling)

P.S.-The preview is not showing the spaces before return but I assure you that all the spaces are proper.


#2

@urja1511,

Please re-edit your Post and mention the error-message !!

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697


#3

Hi,
What is the error that you are getting?

Thank You


#4

Traceback (most recent call last):
File "C:Python\Travlling_cost.py", line 24, in
travelling = trip_cost(n,l,m)
File "C:\Python\Travlling_cost.py", line 20, in trip_cost
return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days) + spending_money
File "C:\Python\Travlling_cost.py", line 14, in rental_car_cost
if days >=7:
TypeError: unorderable types: str() >= int()

'
This is the error that I am getting.


#5

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:
     cost -=50
    elif days>=3 and days<7:
     cost -=20    
    return cost
def trip_cost(city,days,spending_money):
    return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days) + spending_money
n = input("Please Enter the city where you gonna go:")	
l = input("Please Enter the number of days:")
m = input("Please enter the extra spending money:")
travelling = trip_cost(n,l,m)
print (travelling)

Thank You.