コード例 #1
0
ファイル: taxi_simulator.py プロジェクト: Nickwest999/sandbox
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())
コード例 #2
0
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 = SliverServiceTaxi("Limo", 100, 2)
    print(sst, sst.get_fare())
    sst.drive(10)
    print(sst, sst.get_fare())
コード例 #3
0
def main():
    prius = Taxi('Prius', 100)
    prius.drive(40)
    print(prius)
    print("The current fair is ${}".format(prius.get_fare()))
    prius.start_fare()
    prius.drive(100)
    print(prius)
    print("The current fair is ${}".format(prius.get_fare()))
コード例 #4
0
def main():
    taxi1 = Taxi("Prius 1", 100, 1.23)
    taxi1.drive(40)
    print(taxi1)
    print("The current fare is ${}".format(taxi1.get_fare()))
    taxi1.start_fare()
    taxi1.drive(100)
    print(taxi1)
    print("The current fare is ${}".format(taxi1.get_fare()))
コード例 #5
0
def main():
    my_taxi = Taxi('Prius 1', 100)
    my_taxi.drive(40)
    print("Taxi = {}".format(my_taxi.name))
    print("Current fare = ${:.2f}".format(my_taxi.get_fare()))
    my_taxi.start_fare()
    my_taxi.drive(100)
    print("Taxi = {}".format(my_taxi.name))
    print("Current fare = ${:.2f}".format(my_taxi.get_fare()))
    print(Taxi.price_per_km)
コード例 #6
0
def main():
    my_taxi = Taxi("Prius 1", 100)
    my_taxi.drive(40)
    print("Taxi name: {}, Current Fuel {} and Current Fare is ${}".format(
        my_taxi.name, my_taxi.fuel, my_taxi.get_fare()))

    my_taxi.start_fare()
    my_taxi.drive(100)
    print("Taxi name: {}, Current Fuel {} and Current Fare is ${}".format(
        my_taxi.name, my_taxi.fuel, my_taxi.get_fare()))
コード例 #7
0
def main():
    """Test Taxi class."""
    my_taxi = Taxi("Prius", 100)
    my_taxi.drive(40)
    print(my_taxi)
    my_taxi.start_fare()
    my_taxi.drive(40)
    print(my_taxi)
    print("Total cost of trip ${:.2f}".format(my_taxi.get_fare()))
コード例 #8
0
def main():
    new_taxi = Taxi("Prius 1", 100)
    new_taxi.drive(40)
    print(new_taxi)
    new_taxi.start_fare()
    new_taxi.drive(100)
    print(new_taxi)
コード例 #9
0
ファイル: taxi_test.py プロジェクト: Nickwest999/sandbox
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)
コード例 #10
0
def main():
    Prius = Taxi(100, "prius 1")
    Prius.drive(40)
    print(Prius)
    Prius.start_fare()
    Prius.drive(100)
    print(Prius)
コード例 #11
0
def main():
    taxi = Taxi("Prius 1", 100)
    taxi.drive(40)
    print(taxi)
    taxi.start_fare()
    taxi.drive(100)
    print(taxi)
コード例 #12
0
ファイル: test_taxi.py プロジェクト: LukeElliman/Practicals
def main():
    """Code to test a taxi"""
    prius_one = Taxi("Pirus 1", 100)
    prius_one.drive(40)
    print(prius_one)
    prius_one.start_fare()
    prius_one.drive(100)
    print(prius_one)
コード例 #13
0
def main():
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    total_bill = 0

    print("Let's drive!")
    print(MENU_STRING)
    choice = input(">>> ").upper()
    while choice != "Q":
        if choice == "C":
            print("Taxis available:")
            display_taxis(taxis)
            taxi_choice = int(input("Choose taxi: "))
            current_taxi = taxis[taxi_choice]
        elif 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 Choice")
        print(MENU_STRING)
        choice = input(">>> ").upper()

    print("Total trip cost: ${:.2f}".format(total_bill))
    print("Taxis are now:")
    display_taxis(taxis)
コード例 #14
0
def main():

    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]

    current_bill = 0
    total_bill = 0
    current_taxi = ""

    print("Let's drive!")
    menu_option = input("q)uit, c)hoose, d)rive\n>>>").lower()
    while menu_option != 'q':
        if menu_option == 'c':
            display_taxi(taxis)
            chosen_taxi = int(input("Choose taxi: "))
            current_taxi = taxis[chosen_taxi]
            # print(current_taxi)#
            display_bill(total_bill, current_bill)
            menu_option = input("q)uit, c)hoose, d)rive\n>>>").lower()
        if menu_option == 'd':
            travel_distance = int(input("Drive how far?"))
            current_taxi.start_fare()
            current_taxi.drive(travel_distance)
            print("Your {} trip cost you ${:.2f}".format(
                current_taxi.name, current_taxi.get_fare()))
            total_bill += current_taxi.get_fare()
            display_bill(total_bill, current_bill)
            menu_option = input("q)uit, c)hoose, d)rive\n>>>").lower()
コード例 #15
0
ファイル: taxi_simulator.py プロジェクト: Nickwest999/sandbox
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)
コード例 #16
0
def main():
    print("Let's drive!")
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    bill_to_date = 0.0
    taxi = 0
    menu_choice = input(MENU).lower()
    while menu_choice != "q":
        if menu_choice == "c":
            print("Taxis available:")
            for i in range(len(taxis)):
                print(i, "-", taxis[i])
            taxi = int(input("Choose taxi: "))
        elif menu_choice == "d":
            distance = int(input("Drive how far?"))
            taxis[taxi].drive(distance)
            fare = taxis[taxi].get_fare()
            bill_to_date += fare
            print("Your {} trip cost you ${:.2f}".format(
                taxis[taxi].name, fare))
            taxis[taxi].start_fare()
        else:
            print("Invalid menu choice!")
        print("Bill to date: ${0:.2f}".format(bill_to_date))
        menu_choice = input(MENU).lower()

    print("Total trip cost: ${:.2f}".format(bill_to_date))
    print("Taxis are now:")
    for i in range(len(taxis)):
        print(i, "-", taxis[i])
コード例 #17
0
def Main():
    my_taxi = Taxi("Pruis 1", 100)
    my_taxi.drive(40)
    print(my_taxi)
    print(my_taxi.get_fare)
    my_taxi.start_fare()
    my_taxi.drive(100)
    print(my_taxi)
    print(my_taxi.get_fare)
コード例 #18
0
ファイル: test_taxi.py プロジェクト: Mampson/Cp1404
def main():
    """Test taxi (car subclass) features"""

    new_taxi = Taxi("Prius 1", 100)
    new_taxi.drive(40)
    print(new_taxi)
    new_taxi.start_fare()
    new_taxi.drive(100)
    print(new_taxi)
コード例 #19
0
ファイル: taxi_test.py プロジェクト: SILIN-WANG/Sandbox
def main():
    """Test Taxi class."""
    taxi1 = Taxi("Prius 1", 100)
    taxi1.drive(40)
    print(taxi1)

    taxi1.start_fare()  # start a new fare
    taxi1.drive(100)
    print(taxi1)
コード例 #20
0
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)

    print(Taxi.price_per_km)
コード例 #21
0
def main():
    my_taxi = Taxi('Prius 1', 100, 1.23)
    my_taxi.drive(40)
    print(my_taxi)
    print('Taxi Details:{}, current fare:${}'.format(
        my_taxi.name, my_taxi.current_fare_distance))
    my_taxi.start_fare()
    my_taxi.drive(100)
    print('Taxi Details:{}, current fare:${}'.format(
        my_taxi.name, my_taxi.current_fare_distance))
    print(my_taxi)
コード例 #22
0
def main():
    finished = False
    chosen = False
    fare = 0
    taxis = [
        Taxi(100, "Prius"),
        SilverServiceTaxi(100, "Limo", 2),
        SilverServiceTaxi(200, "Hummer", 4)
    ]
    chosen_ride = input("Prius, Limo, Hummer\nChoose your ride(p,l,h):")
    while not finished:
        while not chosen:
            if chosen_ride == "p":
                taxi = taxis[0]
                distance = int(input("how far will you drive? "))
                taxi.drive(distance)
                print(taxi)
                chosen = True
            elif chosen_ride == "l":
                taxi = taxis[1]
                distance = int(input("how far will you drive? "))
                taxi.drive(distance)
                print(taxi)
                chosen = True
            elif chosen_ride == "h":
                taxi = taxis[2]
                distance = int(input("how far will you drive? "))
                taxi.drive(distance)
                print(taxi)
                chosen = True
            else:
                print("invalid ride")
                chosen_ride = input(
                    "Prius, Limo, Hummer\nChoose your ride(p,l,h):")
        fare += taxi.get_fare()
        print("current bill at ${:.2f}".format(fare))

        y_n = input("would you like to drive again (y/n)? ")
        answer = False
        while not answer:
            if y_n == "y":
                chosen_ride = input(
                    "Prius, Limo, Hummer\nChoose your ride(p,l,h):")
                chosen = False
                answer = True
            elif y_n == "n":
                finished = True
                answer = True
            else:
                print("invalid answer")
                answer = False
    print("final Bill: ${:.2f}".format(fare))
コード例 #23
0
def main():
    total_fare_price = 0
    taxis = [
        Taxi("Pruis", 100),
        SilverServiceTaxi("limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    print("Let's drive!")
    print(MENU)
    current_taxi = None
    menu_input = input(">>> ").lower()
    while menu_input != "q":
        if menu_input == "c":
            print("Taxis available: ")
            print_taxis(taxis)
            valid_taxi_number = False
            while not valid_taxi_number:
                try:
                    taxi_choice = int(input("Choose Taxi: "))
                    if taxi_choice > len(taxis) - 1:
                        taxi_choice = int(input("Choose Taxi: "))
                    else:
                        valid_taxi_number = True
                except ValueError:
                    print("Invalid Number")
            print("Bill to date: ${:.2f}".format(total_fare_price))
            current_taxi = taxis[taxi_choice]
        elif menu_input == "d":
            if current_taxi is not None:
                current_taxi.start_fare()
                drive_distance = float(input("Drive how far? "))
                current_taxi.drive(drive_distance)
                trip_price = current_taxi.get_fare()
                print("Your {} trip cost you {}".format(
                    current_taxi.name, current_taxi.get_fare()))
                total_fare_price += trip_price
        else:
            print("Invalid Option")
        print("Bill to date: ${:.2f}".format(total_fare_price))
        print(MENU)
        menu_input = input(">>> ").lower()

    print("Total trip cost: ${:.2f}".format(total_fare_price))
    print_taxis("Taxis are now:")
    print_taxis(taxis)
コード例 #24
0
def main():
    """Build list of taxi objects to choose from and simulate drive and billing"""
    print("Lets Drive! ")
    current_taxi = None
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    total_trip_cost = 0

    menu_choice = get_menu_choice()
    while menu_choice != "q":

        if menu_choice == "c":
            # list taxis
            print_taxis(taxis)
            taxi_number = get_taxi_choice(taxis)
            current_taxi = assign_taxi(taxi_number, taxis)
            print("Bill to date: ${}".format(total_trip_cost))
            menu_choice = get_menu_choice()
        elif menu_choice == "d":
            # drive taxi
            if current_taxi == None:
                print("You must choose a taxi first! ")
                menu_choice = get_menu_choice()
            else:
                print("Drive how far? ")
                desired_drive_distance = get_int_entry()
                current_taxi.drive(desired_drive_distance)
                total_trip_cost = total_trip_cost + current_taxi.get_fare()
                print("Your {} trip cost you: ${} ".format(
                    current_taxi.name, current_taxi.get_fare()))
                print("Bill to date: {} ".format(total_trip_cost))
                menu_choice = get_menu_choice()
        else:
            print("Invalid menu choice please try again")
            menu_choice = get_menu_choice()
    # print total trip cost
    print("Total trip cost: ${} ".format(total_trip_cost))
    # re-print taxis with changed conditions
    print("Taxis are now: \n")
    print_taxis(taxis)
コード例 #25
0
def main():
    """Code to simulate multiple taxis"""
    current_taxi = None
    total_bill = 0
    taxis = [Taxi("Prius", 100), SilverTaxi("Limo", 100, 2), SilverTaxi("Hummer", 200, 4)]
    print(MENU)
    choice = input(">>>").upper()
    while choice != "Q":
        if choice == "C":
            print_taxis(taxis)
            car_choice = get_valid_integer("Choose Taxi: ")
            while car_choice < 0 or car_choice > len(taxis) - 1:
                print(f"Choice must be between 0 and {len(taxis) - 1}")
                car_choice = get_valid_integer("Choose Taxi: ")
            current_taxi = taxis[car_choice]
            print(f"Bill to date ${total_bill}")
            print(MENU)
            choice = input(">>>").upper()
        if choice == "D":
            if current_taxi is None:
                print("You do not have a taxi selected")
                choice = input(">>>").upper()
            else:
                drive_distance = get_valid_integer("Drive how far? ")
                while drive_distance < 0:
                    print(f"Choice must be above 0")
                    drive_distance = get_valid_integer("Drive how far? ")
                current_taxi.drive(drive_distance)
                total_bill += current_taxi.get_fare()
                print(f"Your {current_taxi.name} trip cost ${current_taxi.get_fare()}")
                print(MENU)
                choice = input(">>>").upper()
        else:
            if choice != "Q":
                print("You must choose q,d or c")
                print(MENU)
                choice = input(">>>").upper()
    print(f"Total trip cost: ${total_bill}")
    print("Taxis are now")
    print_taxis(taxis)
コード例 #26
0
def main():
    taxis = [
        Taxi("Prius", 100),
        Silver_Service_Taxi("Limo", 100, 2),
        Silver_Service_Taxi("Hummer", 200, 4)
    ]
    print(MENU)
    choice = input(">>>").upper()
    total_bill = 0
    choosen_taxi = None
    while choice != "C":
        if choice == "A":
            print("Taxis available:")
            taxi_list(taxis)
            taxi_choice = int(input("choose taxi:"))
            choosen_taxi = taxis[taxi_choice]
        elif choice == "B":
            if choosen_taxi is not None:
                drive_taxi(choosen_taxi, total_bill)
        print("Bill to date ${}".format(total_bill))
        print(MENU)
        choice = input(">>>").upper()
コード例 #27
0
def main():
    bill = 0
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    selected_taxi = None
    print("Let's drive!")
    print(MENU)
    menu_choice = input(">>> ").lower()
    while menu_choice != "q":
        if menu_choice == "c":
            print("Taxis available:")
            print(list_taxis(taxis))
            choose_taxi = int(input("Choose taxi: "))
            while choose_taxi > len(taxis) - 1:
                choose_taxi = int(input("Choose taxi: "))
            selected_taxi = taxis[choose_taxi]

        elif menu_choice == "d":
            if selected_taxi is not None:
                selected_taxi.start_fare()
                distance = int(input("Drive how far? "))
                selected_taxi.drive(distance)
                cost = selected_taxi.get_fare()
                print("Your {} trip cost you ${}".format(
                    selected_taxi.name, cost))
                bill += cost
        else:
            print("Invalid option")
        print("Bill choose to date: ${}".format(bill))
        print(MENU)
        menu_choice = input(">>> ").lower()

    print("Total trip cost: ${}".format(bill))
    print("Taxis are now:")
    list_taxis(taxis)
コード例 #28
0
def main():
    """Drive car program"""
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    bill_to_date = 0
    current_taxi = None
    while True:
        print('Let\'s drive!')
        print('(C)hoose Taxi')
        print('(D)rive')
        print('(Q)uit')
        choice = input('>>>').upper()
        if choice == 'C':
            for index, taxi in enumerate(taxis):
                print('{} - {}'.format(index, taxi))

            current_taxi = int(input('Choose taxi: '))
            bill_to_date += taxis[current_taxi].get_fare()
            print('Bill to date: ', round(bill_to_date, 1))
        elif choice == 'D':
            if current_taxi is not None:
                distance = int(input('Drive how far? '))
                taxis[current_taxi].drive(distance)
                print('Your {} trip cost you {}'.format(
                    taxis[current_taxi].name, taxis[current_taxi].get_fare()))
                bill_to_date += taxis[current_taxi].get_fare()
                print('Bill to date: ', round(bill_to_date, 1))
            else:
                print('Please choose a taxi first!')
            pass
        elif choice == 'Q':
            print('Total trip cost: ', round(bill_to_date, 1))
            quit()
        else:
            print('Invalid menu choice')
コード例 #29
0
def main():
    bill = 0
    all_taxis = [Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4)]

    print("Let's Drive!")
    menu_choice = input("q)uit, c)hoose taxi, d)rive \n >>>")
    while menu_choice != "q":
        if menu_choice == "c":
            print("Taxi's available:")
            taxi_display(all_taxis)
            taxi_choice = int(input("Choose taxi: "))
            final_taxi = all_taxis[taxi_choice]
            print(bill)
        elif menu_choice == "d":
            final_taxi.start_fare()
            distance = int(input("Drive how far? \n >>>"))
            final_taxi.drive(distance)
            cost = final_taxi.get_fare()
            print("Your {} trip cost you ${:.2f}".format(final_taxi.name, cost))
            bill += cost
            print("Bill to date: {}".format(bill))
        else:
            print("Total trip cost: {}".format(bill))
コード例 #30
0
from Prac_08.taxi import Taxi

taxi_1 = Taxi("Prius 1", 100)
taxi_1.drive(40)
print(taxi_1)
print("Fare = ${}".format(taxi_1.get_fare()))
taxi_1.start_fare()
taxi_1.drive(100)
print(taxi_1)
print("Fare = ${}".format(taxi_1.get_fare()))