Pull it Together
The code is passed the correct city in the first run ("Charlotte") however, for some reason, when trying to access the object of the same name of my Cities class, the compiler 'forgets' to use the value of the passed string, instead using the string value 'city'.
To prove the bug, add a 'city' object to the Cities class and assign it a numeric value. The error output will change.
The error output from the below code is:
Oops, try again. plane_ride_cost('Charlotte') raised an error: class Cities has no attribute 'city'
The same is true if we instantiate a new Cities instance, by calling
myCities = Cities() and then using
myCities.city - except the error now references the instance instead of the class directly.
Exercise should complete and pass all different city inputs (Charlotte, Tampa, Pittsburgh, Los Angeles).
class Cities: """A class containing all valid cities""" Charlotte = 183 Tampa = 220 Pittsburgh = 222 LosAngeles = 475 def hotel_cost(nights): return 140 * nights def plane_ride_cost(city): if city == 'Los Angeles': city = 'LosAngeles' return Cities.city def rental_car_cost(days): total = days * 40; if days >= 7: total -= 50 elif days >= 3 and days < 7: total -= 20 return total def trip_cost(city, days): return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)