I am trying to learn python using codeacdemy. This was one of their excercises. Basically they had me create 4 different functions that calculated the total cost. But there was no option to ask the user to manually enter in the values. So thats what I am trying to to. The code is right upto the return rental-car_cost part. its just the bottom bit where I am having trouble.
print "this code calculates the total price of a trip, using 4 functions"
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=days*40
if (days>=7):
cost -= 50
elif(days>=3):
cost -=20
return cost
def trip_cost(city,days,spending_money):
return rental_car_cost(days)+hotel_cost(days)+ plane_ride_cost(city)+spending_money
city= raw_input("enter city name")
days= raw_input("enter number of days staying")
spending_money= raw_input("enter spendig money")
print trip_cost(city,days, spending_money)
this was the original code and it rune perfectly fine. All i want to do is have the user enter the values when the code it running.
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=days*40
if (days>=7):
cost -= 50
elif(days>=3):
cost -=20
return cost
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)