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(): 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) 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(): my_taxi = Taxi("Prius 1", 100, 1.23) my_taxi.drive(40) print(my_taxi) my_taxi.start_fare() my_taxi.drive(100) print(my_taxi)
def main(): my_taxi = Taxi('Prius 1', 100) my_taxi.drive(40) print(my_taxi) my_taxi.start_fare() my_taxi.drive(100) print(my_taxi)
def main(): """Test Taxi class.""" my_taxi = Taxi("Prius 1", 100) my_taxi.drive(40) print(my_taxi) my_taxi.start_fare() my_taxi.drive(100) print(my_taxi)
def main(): taxi = Taxi("Prius 1", 100) taxi.drive(40) print("Current fare: {}".format(taxi.get_fare())) taxi.start_fare() taxi.drive(100) print("Current fare: {}".format(taxi.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(): prius_1 = Taxi("Prius 1", 100) prius_1.drive(40) print(prius_1) print(prius_1.get_fare())
from prac8.taxi import Taxi from prac8.silverServiceTaxi import SilverServiceTaxi taxis = [ Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4) ] fares = [] def main(): taxi_choice = 0 print("Lets drive!") valid_input = False while not valid_input: display_menu() choice = input(">>>: ").upper() if choice == 'C': taxi_choice = choose_taxi() elif choice == 'D': drive_taxi(taxi_choice) elif choice == 'Q': print("Taxis are now:") count = 0 for taxi in taxis: print("{} - {}".format(count, taxi)) count += 1 valid_input = True else: