Stuck at trip_cost


#1


https://www.codecademy.com/en/courses/python-beginner-P5YtY/1/6?curriculum_id=4f89dab3d788890003000096#


trip_cost should take exactly three parameters: city, days, and spending_money (in that order).


it should execute correctly.


days=raw_input("Enter number of days:")
days=map(int, days)
city=raw_input("Enter city name:")
spending_money=raw_input("Enter spending money:")
spending_money= map(int, spending_money)
def main(city, days,spending_money):
    trip_cost(city,days,spending_money)
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
        return cost
    elif days >=3:
        cost-=20
        return cost
    else:
        return cost 
def trip_cost(city,days,spending_money):
    car_cost=rental_car_cost(days)
    hotelcost=hotel_cost(days)
    plane_cost=plane_ride_cost(city)
    total_cost=car_cost+hotelcost+plane_ride_cost+spending_money
    print total_cost
if __name__ == "__main__":
    main(city,days,spending_money)


#2

You seem to have some code for testing, does that run correctly? If not, then you've both determined that it doesn't and reproduced a scenario where it misbehaves that you can observe.
Also, typing in test data every time is rather cumbersome, easier to put it into the code, particularly when sharing/asking about the code since others don't know what you're entering.


#3

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