예제 #1
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())
예제 #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 = SilverServiceTaxi("Limo", 100, 2)
    print(sst, sst.get_fare())
    sst.drive(10)
    print(sst, sst.get_fare())
예제 #3
0
def main():
    taxi1 = Taxi("Prius", 100)

    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()))
예제 #4
0
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)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
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
예제 #9
0
def main():
    prius_1 = Taxi("Prius 1", 100)
    prius_1.drive(40)
    print(prius_1.__str__())
    print(prius_1.get_fare())

    prius_1.start_fare()
    prius_1.drive(100)
    print(prius_1.__str__())
    print(prius_1.get_fare())
예제 #10
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.")