def run_tests(): """Run tests to show workings of Car and Taxi classes.""" bus = Car("Datsun", 180) bus.drive(30) print("fuel =", bus.fuel) print("odo =", bus.odometer) bus.drive(55) print("fuel =", bus.fuel) print("odo = ", bus.odometer) print(bus) # drive bus (input/loop is oblivious to fuel) distance = int(input("Drive how far? ")) while distance > 0: travelled = bus.drive(distance) print("{} travelled {}".format(str(bus), travelled)) distance = int(input("Drive how far? ")) t = Taxi("Prius 1", 100) print(t) t.drive(25) print(t, t.get_fare()) t.start_fare() t.drive(40) print(t, t.get_fare()) sst = SilverServiceTaxi("Limo", 100, 2) print(sst, sst.get_fare()) sst.drive(10) print(sst, sst.get_fare())
def main(): taxis = [Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4)] print(MENU) menu_choice = get_menu_choice() while menu_choice != 'q': if menu_choice == 'c': print("Taxis available:") display_taxis(taxis) current_taxi = taxis[get_taxi_choice()] elif menu_choice == 'd': trip_distance = int(input("Drive how far? ")) pre_fare_total = get_current_price([current_taxi]) drove = current_taxi.drive(trip_distance) trip_fare = current_taxi.get_fare() - pre_fare_total print("Your {} trip cost you ${:.2f}".format(current_taxi.name, trip_fare)) print("Bill to date: ${:.2f}".format(get_current_price(taxis))) print(MENU) menu_choice = get_menu_choice() print("Total trip cost: ${:.2f}".format(get_current_price(taxis))) print("Taxis are now:") display_taxis(taxis)
def main(): """Write a taxi simulator program that uses your Taxi and SilverServiceTaxi classes. Each time, until they quit: The user should be presented with a list of available taxis and get to choose one. Then they should say how far they want to drive. At the end of each trip, show them the price and add it to their bill. """ total_bill = 0 taxis = [Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4)] print("Let's drive!") print(MENU) menu_choice = input(">>> ").lower() while menu_choice != "q": if menu_choice == "c": print("Taxis available: ") display_taxis(taxis) # no error-checking taxi_choice = int(input("Choose taxi: ")) current_taxi = taxis[taxi_choice] elif menu_choice == "d": current_taxi.start_fare() distance_to_drive = float(input("Drive how far? ")) current_taxi.drive(distance_to_drive) trip_cost = current_taxi.get_fare() print("Your {} trip cost you ${:.2f}".format(current_taxi.name, trip_cost)) total_bill += trip_cost else: print("Invalid option") print("Bill to date: ${:.2f}".format(total_bill)) print(MENU) menu_choice = input(">>> ").lower() print("Total trip cost: ${:.2f}".format(total_bill)) print("Taxis are now:") display_taxis(taxis)
def main(): silver_taxi = SilverServiceTaxi("Fast Taxi", 100, 2) silver_taxi.drive(18) print(silver_taxi) print("Current fare: ${}".format(silver_taxi.get_fare()))
def main(): """Test SilverServiceTaxi.""" taxi = SilverServiceTaxi("Test Fancy Taxi", 100, 2) taxi.drive(18) print(taxi) print(taxi.get_fare())
def main(): t = SilverServiceTaxi("t", 40, 2) print(t.flagfall) t.drive(20) print(t) print("${:.2f}".format(t.get_fare()))