Misleading/WRONG OOPS, what does this mean, how to fix?


#1

Hi. I'm getting a non-sensical "Oops" message when executing this code.
Message (on this run), printed at bottom of code is:
"Oops, try again.
trip_cost('Tampa', 2) raised an error: invalid literal for int() with base 10: 'Tampa"

Which is kind of weird since I specified Los Angeles as the destination. Code is below, accompanied
by my output statements from execution. What does this foolish tool want? (And I'm not talking
about Python when I say "foolish".)

def hotel_cost(nights):
    return 140 * nights
    
#num_nights = raw_input("How many nights are you staying? ")
#cost = hotel_cost(int(num_nights))
#print "Cost is: " + str(cost)

def plane_ride_cost(city):
    if (city == "Charlotte"):
        cost = 183
    elif (city == "Tampa"):
        cost = 220
    elif (city == "Pittsburgh"):
        cost = 222
    elif (city == "Los Angeles"):
        cost = 475
    else:
        cost = 3000
    return cost

#dest = raw_input("Where are you flying?  ") 
#flight_trip_cost = plane_ride_cost(dest)
#print "Cost to destination: " + dest + " is " + str(flight_trip_cost) + " dollars."

def rental_car_cost(days):
    if (days >= 7):
        discount = 50
    elif (days >= 3 and days < 7):
        discount = 20
    else:
        discount = 0
    return (int(days) * 40) - discount

#number_of_days = raw_input("How many days are you renting? ")
#car_rent = rental_car_cost(int(number_of_days))
#print "Cost of rental car for trip is:  " + str(car_rent) + " dollars."

def trip_cost(num_days, location):
    print " "
    print "Final tally:"
    car_cost = rental_car_cost(num_days)
    print "Car rental: " + str(car_cost) + " dollars."
    housing_cost = hotel_cost(num_days)
    print "Hotel cost: " + str(housing_cost) + " dollars."
    plane_cost = plane_ride_cost(location)
    print "Plane ticket: " + str(plane_cost) + " dollars."
    tally = int(car_cost) + int(housing_cost) + int(plane_cost)

    print "All for a grand total of: " + "$" + str(tally) + ".00" + " dollars."
    
num_days = int(raw_input ("How many days total for your trip?"))
location = raw_input ("Whereabouts ya going'?")

print ("num_days is:  %s") % num_days
print ("location is:  %s") % location
trip_cost (num_days, location)

My printed output, which is correct:

How many days total for your trip? 5
Whereabouts ya going'? Los Angeles
num_days is: 5
location is: Los Angeles

Final tally:
Car rental: 180 dollars.
Hotel cost: 700 dollars.
Plane ticket: 475 dollars.
All for a grand total of: $1355.00 dollars.
None


#2

OK. Here's how STUPID this one is. Because the instructions told you to call trip_cost with
location and days, in that order, that's the only order it will accept. Calling it with
days and location yields an ERROR for this tool. Yuck!


#3

And who needs to follow instructions, right?


#4

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