Пример #1
0
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.type, 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)
Пример #2
0
def play_game():
    """
    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
            try:
                taxi_choice = int(input("Choose taxi: "))
                current_taxi = taxis[taxi_choice]
            except:
                print("Invalid Option")
        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.car_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)
Пример #3
0
def main():
    current_taxi = None
    bill_to_date = 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: ")
            for taxi_number, taxi in enumerate(taxis):
                print("{} - {}".format(taxi_number, taxi))
            taxi_choice = int(input("Choose Taxi: "))
            current_taxi = taxis[taxi_choice]
            print("Bill to date: ${:.2f}".format(bill_to_date))
            print(MENU)
            menu_choice = input(">>> ").lower()
        elif menu_choice == "d":
            current_taxi.start_fare()
            distance = float(input("Drive how far? "))
            current_taxi.drive(distance)
            drive_cost = current_taxi.get_fare()
            print("Your {} trip cost you ${:.2f}".format(
                current_taxi.name, drive_cost))
            bill_to_date += drive_cost
            print("Bill to date: ${:.2f}".format(bill_to_date))
            print(MENU)
            menu_choice = input(">>> ").lower()
        else:
            print("Invalid option")
            print("Bill to date: ${:.2f}".format(bill_to_date))
            print(MENU)
            menu_choice = input(">>> ").lower()
    print("Total trip cost: ${:.2f}".format(bill_to_date))
    taxi_number = 0
    for taxi in taxis:
        print("{} - {}".format(taxi_number, taxi))
        taxi_number += 1
Пример #4
0
def test():
    # 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(bus)
    #     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())
Пример #5
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 = SilverServiceTaxi("Limo", 100, 2)
    print(sst, sst.get_fare())
    sst.drive(10)
    print(sst, sst.get_fare())
Пример #6
0
"""
Practical 8 CP1404
Rhys Donaldson
13581558
"""
from prac_8.silver_service_taxi import SilverServiceTaxi
from prac_8.taxi import Taxi

current_taxi = None
current_total = 0

taxis = [
    Taxi("Prius", 100),
    SilverServiceTaxi("Limo", 100, 2),
    SilverServiceTaxi("Hummer", 200, 4)
]
choice = input("Let's drive! \n q)uit, c)hoose, d)rive \n >>> ")
while choice is not "q":
    if choice == "c":
        print("Taxis available")
        for i, taxi in enumerate(taxis):
            print("{} - {}".format(i, taxi.__str__()))
        current_taxi = taxis[int(input("Choose taxi:"))]
    elif choice == "d":
        current_taxi.drive(int(input("Drive how far?")))
        current_total += current_taxi.get_fare()
        print("Your {} trip cost you ${:.2f} \nBill to date: ${:.2f}".format(
            current_taxi.name, current_taxi.get_fare(), current_total))
        current_taxi.start_fare()
    else:
        print("That is not an option.")
Пример #7
0
def main():
    # Test SilverServiceTaxi
    taxi = SilverServiceTaxi("Test fancy silver service Taxi", 100, 2)
    taxi.drive(18)
    print(taxi)
    print(taxi.get_fare())
def main():
    taxi = SilverServiceTaxi("Hummer", 100, 2)
    taxi.drive(18)
    print(taxi)
    print("${}".format(taxi.gets_fare()))
def main():
    taxi = SilverServiceTaxi("Test Fancy Taxi", 100, 2)
    taxi.drive(18)
    print(taxi)
    print(taxi.get_fare())