def main(): # test Taxi class test_taxi = Taxi("Prius 1", 100) print(test_taxi) # drive 40km, print details, current fare test_taxi.drive(40) print("{} : Price: ${}".format(test_taxi, test_taxi.get_fare())) # restart meter, drive 100 test_taxi.start_fare() test_taxi.drive(100) print("{} : Price: ${}\n".format(test_taxi, test_taxi.get_fare())) # test UnreliableCar class test_unrel = UnreliableCar("UnrelCar", 100, 60) print("{} : Reliability: {}".format(test_unrel, test_unrel.reliability)) test_unrel.drive(40) print("{} : Reliability: {}\n".format(test_unrel, test_unrel.reliability)) # test SilverServiceTaxi class test_silver = SilverServiceTaxi("SilverTaxi", 100, 2) print(test_silver) test_silver.drive(10) print("Current fare: ${:.2f}".format(test_silver.get_fare()))
def run_tests(): 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) 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(): taxi1 = Taxi("Prius 1", 100) taxi1.drive(40) print(taxi1) taxi1.start_fare() taxi1.drive(100) print(taxi1)
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(): taxis = [ Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4) ] current_bill = 0 chosen_taxi = taxis[0] print("Let's Drive!") print(MENU) menu_choice = input(">>> ").lower() while menu_choice != 'q': if menu_choice == 'c': chosen_taxi = get_taxi_choice(taxis) chosen_taxi.start_fare() elif menu_choice == 'd': drive_taxi(chosen_taxi) print("Your {} trip cost you ${:.2f}".format( chosen_taxi.name, chosen_taxi.get_fare())) current_bill += chosen_taxi.get_fare() else: print("Invalid Menu Choice") print("Bill to date: ${:.2f}".format(current_bill)) print(MENU) menu_choice = input(">>> ").lower()
def main(): taxis = [ Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4) ] print("Let's drive!") menuChoice = input("q)uit, c)hoice, d)rive\n>>> ").lower() while menuChoice != 'q': if menuChoice == 'c': print("Taxis availiable") print_taxis(taxis) taxiChoice = int(input("Choose taxi: ")) taxi = taxis[taxiChoice] print("Bill to date: ${:.2f}".format(taxi.get_fare())) elif menuChoice == 'd': driveDistance = int(input("Drive how far? ")) taxi.drive(driveDistance) print("Your {} trip cost you ${:.2f}".format( taxi.name, taxi.get_fare())) print("Bill to date: ${:.2f}".format(taxi.get_fare())) else: print("invalid choice") menuChoice = input("q)uit, c)hoice, d)rive\n>>> ").lower() print("Taxis are now:") print_taxis(taxis)
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) # 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(): taxis = [ Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4) ] bill_to_date = 0 print("Let's Drive!") print(MENU) menu_choice = input(">>>") while menu_choice != "q": if menu_choice == "c": for i, taxi in enumerate(taxis): print(i, taxi) taxi_choice = int(input("Choose taxi:")) taxis[taxi_choice].start_fare() print("Bill to date: ${:.2f}".format(bill_to_date)) elif menu_choice == "d": distance = int(input("Drive how far: ")) taxis[taxi_choice].drive(distance) print("Your {} trip cost you ${:.2f}".format( taxis[taxi_choice].name, taxis[taxi_choice].get_fare())) bill_to_date += taxis[taxi_choice].get_fare() print("Bill to date: ${:.2f}".format(bill_to_date)) print(MENU) menu_choice = input(">>>") print("Total trip cost: ${:.2f}".format(bill_to_date)) print("Taxis are now: ") for i, taxi in enumerate(taxis): print(i, taxi)
def main(): current_taxi = None taxis = [ Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4) ] total_fare = 0 menu = "q)uit, c)hoose taxi, d)rive" print("Let's Drive \n" + menu) user_choice = input(">>> ").upper() while user_choice != 'Q': if user_choice == 'C': print("Taxi's available: ") display_taxis(taxis) chosen_taxi = int(input("Choose Taxi: ")) current_taxi = taxis[chosen_taxi] elif user_choice == "D": current_taxi.start_fare() distance = float(input("Drive how far? ")) current_taxi.drive(distance) fare = current_taxi.get_fare() print("Your {} trip cost you {}".format(current_taxi.name, fare)) total_fare += fare else: print("Invalid Option") print("Bill to date: ${:.2f}".format(total_fare)) print(menu) user_choice = input(">>> ").upper() print("Total trip cost: ${:.2f}".format(total_fare)) print("Taxis are now: ") display_taxis(taxis)
def main(): prius = Taxi("Prius 1", 100) prius.drive(40) print(prius) print("Current fare: ${}".format(prius.get_fare())) prius.start_fare() prius.drive(100) print(prius) print("Current fare: ${:.2f}".format(prius.get_fare())) Herbie = UnreliableCar("herbie", 100, 10.00) Herbie.drive(50) print(Herbie) Hummer = SilverServiceTaxi("Hummer", 200, 4) print(Hummer) generic = SilverServiceTaxi("Generic", 200, 2) generic.start_fare() generic.drive(10) print("Current fare: ${:.2f}".format(generic.get_fare()))
def main(): taxis = [ Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4) ] bill_to_date = 0 current_taxi = None print() print(MENU) user_input = input(">>>").upper() while user_input != "Q": if user_input == "C": print("Taxis available") for count, taxi in enumerate(taxis): print("{} - {}".format(count, taxi)) valid_input = False while not valid_input: try: user_choice = int(input("Choose taxi: ")) if user_choice < 0 or user_choice > count: print("invalid taxi number") else: valid_input = True except ValueError: print("invalid choice") current_taxi = taxis[user_choice] print("Bill to date: ${:.2f}".format(float(bill_to_date))) elif user_input == "D": if current_taxi is not None: distance = int(input("Drive how far? ")) current_taxi.start_fare() current_taxi.drive(distance) print("Your {} trip cost you ${:.2f}".format( current_taxi.name, current_taxi.get_fare())) bill_to_date += current_taxi.get_fare() print("Bill to date: ${:.2f}".format(float(bill_to_date))) else: print("no car") else: print("Invalid menu choice") print(MENU) user_input = input(">>>").upper() print("Total trip cost you ${:.2f}".format(bill_to_date)) "Taxis are now:" for count, taxi in enumerate(taxis): print("{} - {}".format(count, taxi))
def main(): # Prius = Taxi("Prius", 100) # print(Prius) # Prius.drive(40) # Prius.current_fare_distance = 100 # print(Prius) # # dodge = UnreliableCar('dodge', 100) # print(dodge) # if dodge.drive(130): # print('It worked') # else: # print("It failed") # print(dodge) # # taxi = SilverServiceTaxi('taxi',200,4) # taxi.drive(10) # print(taxi) taxis = [Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4)] bill = 0 menu_choice = get_menu() while menu_choice != "q": if menu_choice == "c": taxi_choice = run_taxi_choice(taxis) print("Bill to date: ${:.2f}".format(bill)) menu_choice = get_menu() elif menu_choice == "d": bill = run_drive(bill, taxi_choice) menu_choice = get_menu() print("Total trip cost: ${:.2f}".format(bill)) print("Taxis are now:") counter = 0 for taxi in taxis: print(counter, "-", taxis[counter]) counter += 1
def main(): bill = 0 taxis = [ Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4) ] print("Let's drive!") current_taxi = None print("q)uit, c)hoose taxi, d)rive") menu_choice = str(input(">>> ")).lower() while menu_choice != "q": if menu_choice == "c": print("Taxis Avaliable:") for i, taxi in enumerate(taxis): print("{} - {}".format(i, taxi)) taxi_choice = int(input("Choose taxi: ")) current_taxi = taxis[taxi_choice] print(current_taxi) print("Bill to date: ${:.2f}".format(bill)) elif menu_choice == "d": current_taxi.start_fare() get_distance = int(input("Drive how far? ")) current_taxi.drive(get_distance) print("Your {} trip cost you ${:.2f}".format( current_taxi.name, current_taxi.get_fare())) bill = bill + current_taxi.get_fare() print("Bill to date: ${:.2f}".format(bill)) else: print("Error, please enter a valid input.") print("q)uit, c)hoose taxi, d)rive") menu_choice = str(input(">>> ")).lower() print("Total trip cost: ${}".format(bill)) print("Taxis are now:") for i, taxi in enumerate(taxis): print("{} - {}".format(i, taxi))
from Prac08.taxi import Taxi new_taxi = Taxi("Prius 1", 100) print(new_taxi) new_taxi.start_fare() new_taxi.drive(40) print(new_taxi) print(new_taxi.get_fare()) new_taxi.start_fare() new_taxi.drive(100) print(new_taxi) print(new_taxi.get_fare())
def main(): prius_one = Taxi("Prius 1", 100) prius_one.start_fare() prius_one.drive(40) prius_one.get_fare() print(prius_one) prius_one.start_fare() prius_one.add_fuel(100) prius_one.drive(100) print(prius_one) ute = UnreliableCar("Clunker", 100, 50) ute.drive(10) print(ute) hummer = SilverServiceTaxi("Hummer", 100, 2) hummer.drive(10) print(hummer) print(hummer.get_fare())
def main(): MENU = "q)uit, c)hoose taxi, d)rive" taxis = [ Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4) ] trip_cost = 0 total_distance = 0 taxi_choice = "" print("Let's drive!") print(MENU) user_choice = input(">>> ").lower() while user_choice != "q": if user_choice == "c": valid_input = False while not valid_input: try: print("Taxis available:") get_taxi_menu(taxis) taxi_choice = int(input("Choose taxi: ")) if taxi_choice <= len(taxis) - 1: valid_input = True else: print("Not a valid choice") except: print("Not a valid number") print("{} selected.".format(taxis[taxi_choice])) print("Bill to date: ${:.2f} Distance driven: {}Km".format( trip_cost, total_distance)) print(MENU) user_choice = input(">>> ").lower() elif user_choice == "d" and taxi_choice == "": print("No taxi selected") print(MENU) user_choice = input(">>> ").lower() elif user_choice == "d" and taxi_choice != "": valid_input = False while not valid_input: try: distance = int(input("Drive how far? ")) valid_input = True except: print("Not a valid number.") taxis[taxi_choice].start_fare() km_driven = taxis[taxi_choice].drive(distance) total_distance += km_driven trip_cost += taxis[taxi_choice].get_fare() print("Your {}Km {} trip cost you ${:.2f}".format( km_driven, taxis[taxi_choice], taxis[taxi_choice].get_fare())) print("Bill to date: ${:.2f} Distance driven: {}Km".format( trip_cost, total_distance)) print(MENU) user_choice = input(">>> ").lower() else: print("Not a valid choice") print(MENU) user_choice = input(">>> ").lower() print("Total trip cost: ${:.2f} & distance driven {}Km".format( trip_cost, total_distance)) print("Taxis are now:") get_taxi_menu(taxis)
from Prac08.taxi import Taxi newTaxi = Taxi("Prius 1", 100) newTaxi.drive(40) print(newTaxi) print("Your fare: ${:.2f}".format(newTaxi.get_fare())) newTaxi.start_fare() newTaxi.drive(100) print(newTaxi) print("Your fare: ${:.2f}".format(newTaxi.get_fare()))
def main(): my_taxi = Taxi("Prius 1", 100) my_taxi.drive(40) print(my_taxi) my_taxi.drive(100) print(my_taxi)
""" test taxi CP1404 Practical """ from Prac08.taxi import Taxi prius = Taxi("Prius 1", 100) prius.drive(40) prius.start_fare() prius.drive(100) print(prius.get_fare())
from Prac08.taxi import SilverServiceTaxi TOP_MENU = "q)uit c)hoose taxi d)rive\n>>> " def print_available_taxis(taxis): for this_taxi in range(0, len(taxis)): print("{} - ".format(this_taxi), taxis[this_taxi]) def print_bill(bill_value): print("Bill to date ${:.2f}".format(bill_value)) my_taxis = [ Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4) ] print("Let's drive!") total_bill = 0.00 menu_selection = '' user_taxi = '' while menu_selection != 'q': if menu_selection == 'c': print_available_taxis(my_taxis) taxi_selection = int(input("Choose taxi: ")) user_taxi = my_taxis[taxi_selection]