Example #1
0
def main():

    Prius_1 = Taxi("Prius 1", 100)
    Prius_1.drive(60)
    print(Prius_1.__str__())
    print(Prius_1.get_fare())
    Prius_1.drive(100)
    print(Prius_1.__str__())
    print(Prius_1.get_fare())
Example #2
0
def main():
    taxi = Taxi('Prius 1', 100)
    taxi.drive(40)
    print(taxi)
    print('fare = ${}'.format(taxi.get_fare()))
    taxi.start_fare()
    taxi.drive(100)
    print(taxi)
    print('fare = ${}'.format(taxi.get_fare()))
Example #3
0
def main():
    taxi = Taxi("Prius 1", 100)
    taxi.drive(40)
    print(taxi)
    print("Fare: ${:.2f}".format(taxi.get_fare()))
    taxi.start_fare()
    taxi.drive(100)
    print(taxi)
    print("Fare: ${:.2f}".format(taxi.get_fare()))
Example #4
0
def main():
    taxi_p = Taxi("Prius 1", 100)
    taxi_p.drive(40)
    print(taxi_p)
    print("The fare is $" + str(taxi_p.get_fare()))
    taxi_p.start_fare()
    taxi_p.drive(100)
    print(taxi_p)
    print("The fare is $" + str(taxi_p.get_fare()))
def main():
    taxi = Taxi("Prius 1", 100)
    taxi.drive(40)
    print(taxi.__str__())
    print("Taxi's current fare: {}".format(taxi.get_fare()))
    taxi.start_fare()
    taxi.drive(100)
    print("Taxi detail - Name: {}, fuel: {}, price per km: {}".format(taxi.name, taxi.fuel, taxi.price_per_km))
    print("Taxi's current fare: {}".format(taxi.get_fare()))
def main():

    taxi = Taxi('prius_1', 100)
    taxi.drive(40)

    print(
        'Expect that Prius 1 has 60 liters of fuel, and fair costs $49.20 - '
        'Got, {self.name}, has {self.fuel} LTRS of fuel'.format(self=taxi),
        ',Fare Costs ${:.2f}'.format(taxi.get_fare()))
def main():
    """test the 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("Current fair is: $", my_taxi.get_fare())
def main():
    """
    Write a taxi simulator code which uses the taxi and silverservice classes.
    Each time untill the user quits:
    1. The user should be presented with a list of available taxis to get and choose one.
    2. The user would then state how far they would want to drive it.
    3. At the end of the user's trip, show the price and add it to their bill
    """

    bill = 0
    taxis = [
        Taxi("Prius", 100),
        Taxi("Camry", 150),
        SilverService("Mercedes S500L", 200, 4),
        SilverService("Tesla Model S", 200, 6)
    ]

    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))
            bill += trip_cost
        else:
            print("Invalid option")
        print("Bill to date: ${:.2f}".format(bill))
        print(menu)
        menu_choice = input(">>> ").lower()

    print("Total Trip Cost: ${:2f}".format(bill))
    print(menu)
    menu_choice = input(">>> ").lower()
Example #9
0
def main():

    my_taxi = Taxi("Prius 1", 100)
    my_taxi.drive(40)
    print(my_taxi)
    my_fare = my_taxi.get_fare()
    print(my_fare)
    my_taxi.start_fare()
    my_taxi.drive(100)
    print(my_taxi)
def main():
    """..."""
    prius = Taxi("prius", 100)
    limo = SilverServiceTaxi("Limo", 100, 2)
    hummer = SilverServiceTaxi("Hummer", 200, 4)
    print(prius, "\n", limo, "\n", hummer)
    print(MENU)

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

    bill_to_date = 0

    while MENU != "Q":
        if MENU == "C":
            print("Taxis available:")
            for number, current_taxi in enumerate(taxis):
                print(f"{number} - {current_taxi}")

            choose_taxi = int(input("Choose current_taxi: "))

            current_taxi = taxis[choose_taxi]
            print(current_taxi)

            print(f"Bill to date: ${bill_to_date:.2f}")

        elif MENU == "D":
            drive_taxi = int(input("Drive how far? "))
            current_taxi.drive(drive_taxi)

            print(
                f"Your {current_taxi.name} trip cost you ${current_taxi.get_fare()}"
            )
            bill_to_date += current_taxi.get_fare()

        else:
            print("Invalid input error message")

        print(MENU)
Example #11
0
def main():
    """Test taxi program"""
    my_taxi = Taxi("Prius 1", 100)
    my_taxi.drive(40)

    print(my_taxi.get_fare())
    print(my_taxi)
    print(my_taxi.start_fare())
    my_taxi.drive(100)
    print(my_taxi)
Example #12
0
def main():
    my_taxi = Taxi("Prius 1", 100)

    my_taxi.drive(40)
    print(my_taxi)
    print("Current Fare: ${:.2f}".format(my_taxi.get_fare()))
    my_taxi.start_fare()
    my_taxi.drive(100)
    print(my_taxi)
    print("Current Fare: ${:.2f}".format(my_taxi.get_fare()))
def main():
    """Test the Taxi class."""
    prius = Taxi('Prius 1', 100)
    prius.drive(40)
    print(prius)
    print("The current fare is ${:.2f}".format(prius.get_fare()))
    prius.start_fare()
    prius.drive(100)
    print(prius)
    print("The current fare is ${:.2f}".format(prius.get_fare()))
Example #14
0
def main():
    bill = 0.00
    Menu = "q)uit, c)hoose taxi, d)rive"
    print("Let's drive!")
    print(Menu)
    print("Bill to date: ${}".format(bill))

    choice = str(input(">>>"))
    choice.lower()

    while choice != "q":
        if choice.lower() == "c":
            print("Taxis available: ")
            print(
                "0 - Prius, fuel=100, odometer=0, 0km on current fare, $1.23/km"
                "\n"
                "1 - Limo, fuel=100, odometer=0, 0km on current fare, $2.46/km plus flagfall of $4.50"
                "\n"
                "2 - Hummer, fuel=200, odometer=0, 0km on current fare, $4.92/km plus flagfall of $4.50"
            )
            car_choose = int(input("Choose car:"))
            if car_choose == 0:
                distance = int(input("Drive how far?"))
                taxi0 = Taxi("Prius 1", 100)
                taxi0.drive(distance)
                print("Bill to date: ${}".format(taxi0.get_fare()))
                bill += taxi0.get_fare()
                print(Menu)
                print("Bill to date: ${}".format(bill))
                choice = str(input(">>>"))
                choice.lower()

            elif car_choose == 1:
                distance = int(input("Drive how far?"))
                taxi1 = Silver_service_taxi("Limo", 100, 2)
                taxi1.drive(distance)
                print("Bill to date: ${}".format(taxi1.get_fare()))
                print(Menu)
                print("Bill to date: ${}".format(bill))
                choice = str(input(">>>"))
                choice.lower()

            elif car_choose == 2:
                distance = int(input("Drive how far?"))
                taxi2 = Silver_service_taxi("Limo", 100, 2)
                taxi2.drive(distance)
                print("Bill to date: ${}".format(taxi2.get_fare()))
                print(Menu)
                print("Bill to date: ${}".format(bill))
                choice = str(input(">>>"))
                choice.lower()

            else:
                print("Invalid option")
                print("Bill to date: ${})".format(bill))
Example #15
0
def main():
    """This program is modified version after Inheriting Enhancements"""

    taxi = Taxi(100, "Prius 1")
    taxi.drive(40)
    print(taxi)
    print("Fare ={:.2f}".format(taxi.get_fare()))
    taxi.start_fare()
    taxi.drive(100)
    print()
    print(taxi)
    print("Fare ={:.2f}".format(taxi.get_fare()))
Example #16
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("odometer =", bus.odometer)

    bus.drive(55)

    print("fuel =", bus.fuel)

    print("odometer = ", 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())
Example #17
0
def main():
    """
    print taxi information
    """
    prius_taxi = Taxi("Prius 1", 100)

    prius_taxi.drive(40)  # Drive the taxi 40m
    print(prius_taxi)  # print the taxi's current details and the current fare
    print(" +-- Current fare {:.2f}".format(prius_taxi.get_fare()))

    prius_taxi.start_fare()  # restart the meter (start a new fare)
    prius_taxi.drive(100)
    print(prius_taxi)
    print(" +-- Current fare {:.2f}".format(prius_taxi.get_fare()))
Example #18
0
def main():
    taxi = Taxi("Prius 1", 100, 1.23)

    taxi.drive(40)

    print(taxi)
    print("The current fare is ", taxi.get_fare())

    taxi.drive(100)

    print(taxi)
    print("The current fare is ", taxi.get_fare())

    print(taxi.price_per_km)
Example #19
0
def main():

    name = input("Name: ")
    fuel = int(input("Fuel: "))
    #price_per_km = float(input("Price per km $: "))

    taxi1 = Taxi(name, fuel)
    taxi1.drive(40)
    print("TEST2", taxi1)
    current_fare = taxi1.get_fare()
    print("TEST3", current_fare)
    taxi1.start_fare()
    taxi1.drive(100)
    print("TEST4", taxi1)
Example #20
0
def main():
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    taxi_choice = ""
    bill_total = 0.0
    print("Let's drive!")
    print("q)uit, c)hoose taxi, d)rive")
    menu_choice = input(">>> ").lower()
    while menu_choice != "q":
        if menu_choice == "c":
            print("Taxis available:")
            for index, taxi in enumerate(taxis):
                print("{} - {}".format(index, taxi))
            taxi_choice = int(input("Choose taxi: "))
            if 0 <= taxi_choice > len(taxis) - 1:
                print("Invalid taxi choice")
                taxi_choice = ""
            else:
                current_taxi = taxis[taxi_choice]
        elif menu_choice == "d":
            if taxi_choice == "":
                print("You need to choose a taxi before you can drive")
            else:
                current_taxi.start_fare()
                driving_distance = int(input("Drive how far? "))
                current_taxi.drive(driving_distance)
                current_fare = current_taxi.get_fare()
                bill_total += current_fare
                print("Your {} trip cost you ${:.2f}".format(
                    current_taxi.name, current_fare))
        else:
            print("Invalid option")
        print("Bill to date: ${:.2f}".format(bill_total))
        print("q)uit, c)hoose taxi, d)rive")
        menu_choice = input(">>> ").lower()
    print("Total trip cost ${:.2f}".format(bill_total))
    print("Taxis are now:")
    for index, taxi in enumerate(taxis):
        print("{} - {}".format(index, taxi))
Example #21
0
def main():
    """
    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 _get_states(self):
        states = {}
        state_to_no = {}
        no_to_state = {}
        state_count = 0
        no_of_dests = self.no_of_rows * self.no_of_cols
        no_of_locs = no_of_dests + 1  #+ 1 for being in taxi

        #What a mess - think of a way to eliminate the nestedness
        for taxi_loc in range(no_of_dests):
            for pass1_loc in range(no_of_locs):
                for pass2_loc in range(no_of_locs):
                    for pass1_dest in range(no_of_dests):
                        for pass2_dest in range(no_of_dests):
                            #if pass1_loc == pass1_dest == pass2_loc == pass2_dest: continue
                            state = self.encode(taxi_loc, pass1_loc, pass2_loc,
                                                pass1_dest, pass2_dest)

                            taxi = Taxi(taxi_loc, 0, self.taxi_max_capacity)
                            pass1 = Passenger(1, pass1_loc, pass1_dest)
                            pass2 = Passenger(2, pass2_loc, pass2_dest)

                            if pass1_loc == self.position_in_taxi:
                                taxi.pickup_passenger(pass1)
                            if pass2_loc == self.position_in_taxi:
                                taxi.pickup_passenger(pass2)
                            if pass1_loc == pass1_dest:
                                taxi.pickup_passenger(pass1)
                                taxi.drop_passenger(pass1)
                            if pass2_loc == pass2_dest:
                                taxi.pickup_passenger(pass2)
                                taxi.drop_passenger(pass2)

                            states[state] = [taxi, pass1, pass2]

                            state_to_no[state] = state_count
                            no_to_state[state_count] = state

                            state_count = state_count + 1

        return states, state_to_no, no_to_state
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)
            finished = False
            while finished is False:
                try:
                    taxi_choice = int(input("Choose taxi: "))
                    finished = True
                except ValueError:
                    print("please enter number")
                    finished = False
            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)
Example #24
0
def main():
    total = 0
    menu_choices = "q)uit, c)hoose, d)rive"
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    current_taxi = None
    print("Let's Drive")
    print(menu_choices)
    menu_choice = input(">>> ").lower()
    while menu_choice != "q":
        if menu_choice == "c":
            choose_taxi(taxis)
            taxi_choice = int(input("Choose taxi: "))
            try:
                current_taxi = taxis[taxi_choice]
            except IndexError:
                print("Invalid taxi choice")

        elif menu_choice == "d":
            if current_taxi:
                current_taxi.start_fare()
                drive_distance = float(input("Drive how far? "))
                current_taxi.drive(drive_distance)
                cost = current_taxi.get_fare()
                print(f"Your {current_taxi.name} trip cost you ${cost:.2f}")
                total += cost

            else:
                print("You need to choose a taxi before you can drive")
        else:
            print("Invalid Option")

        print(f"Bill to date : ${total:.2f}")
        print(menu_choices)
        menu_choice = input(">>> ").lower()

    print("Taxis are now: ")
    choose_taxi(taxis)
def main():
    """Simulate taxi service using Taxi and SilverServiceTaxi Classes."""
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    current_taxi = None
    bill_to_date = 0

    print("Let's drive!")
    print(MENU)
    choice = input(">>> ")
    while choice.lower() != 'q':
        if choice.lower() == 'c':
            print("Taxis available:")
            taxis_available(taxis)
            current_taxi = get_valid_taxi(taxis)
        elif choice.lower() == 'd':
            if current_taxi:  # Check that there is a currently selected taxi
                if current_taxi.fuel == 0:  # Check if the selected taxi is out of fuel
                    print(
                        "Sorry, that taxi is all out of fuel. Please choose another Taxi first."
                    )
                else:
                    distance = get_valid_distance()
                    current_taxi.start_fare()
                    current_taxi.drive(distance)
                    trip_fare = current_taxi.get_fare()
                    print("Your {} trip cost you ${:.2f}".format(
                        current_taxi.name, trip_fare))
                    bill_to_date += trip_fare
            else:
                print("No taxi selected, please choose a taxi first")
        else:
            print("Invalid choice")
        print("Bill to date: ${:.2f}".format(bill_to_date))
        print(MENU)
        choice = input(">>> ")
    print("Taxis are now:")
    taxis_available(taxis)
Example #26
0
def main():
    taxis = [Taxi("Prius 1", 100), Limo("Limo", 200, 2), SilverStarTaxi("Silver Star Hummer", 200, 2)]
    print("Let's Drive!")
    menuselection = menu()
    choice = menuselection
    print(choice)
    bill_to_date = 0
    while choice != 'q':
        if bill_to_date > 0:
            print(bill_to_date)
        if menuselection == "c":
            carnum = choose_car(taxis)
            print(taxis[carnum])
            car = taxis[carnum]
        elif menuselection == 'd':
            distance = int(input("Drive How far?"))
            car.drive(distance)
            bill_to_date += car.get_fare()
            print("Your bill to date is: {}".format(bill_to_date))
        menuselection = menu()
        choice = menuselection
Example #27
0
def main():
    total_bill = 0
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    current_taxi = None
    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: "))
            try:
                current_taxi = taxis[taxi_choice]
            except IndexError:
                print("Invalid taxi choice")
        elif menu_choice == "d":
            if current_taxi:
                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("You need to choose a taxi before you can drive")
        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():
    print("Let's drive!")
    taxis = [
        Taxi("Prius", 100),
        SilverServiceTaxi("Limo", 100, 2),
        SilverServiceTaxi("Hummer", 200, 4)
    ]
    current_taxi = None
    bill = 0.0
    command = ''
    while command.lower() != 'q':
        print(MENU)
        command = input(">>> ").lower()[0]
        if command == 'd':
            if current_taxi is None:
                print("Please select a taxi first.")
            else:
                distance = input("Distance: ")
                while not distance.isdigit():
                    distance = input("Please enter a valid distance: ")
                print("Distance driven:", current_taxi.drive(int(distance)))
                print(f"Your {current_taxi.name} trip cost you:",
                      current_taxi.get_fare())
                bill += current_taxi.get_fare()
                print("Bill to date:", bill)
        elif command == 'c':
            print("Taxis available:\n" + list_taxis(taxis))
            done = False
            while not done:
                index = input("Choose taxi: ")
                if index.isdigit():
                    if int(index) > 0 and int(index) <= len(taxis):
                        done = True
            current_taxi = taxis[int(index) - 1]
            print(str(current_taxi))
            current_taxi.start_fare()
    print(f"Total trip cost: {bill:.2f}" + '\nTaxis are now:\n' +
          list_taxis(taxis))
def main():
    """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
    current_taxi = None
    taxis = [Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4)]
    print("Let's drive!")
    print(MENU)
    option = input(">>>").lower()
    while option != 'q':
        if option == 'c':
            print('Taxis available:')
            display_taxis(taxis)
            current_taxi_num = int(input("Choose taxi: "))
            while current_taxi_num not in range(len(taxis)):
                current_taxi_num = int(input("Choose taxi: "))
            current_taxi = taxis[current_taxi_num]
            print("Bill to date: ${:.2f}".format(total_bill))
            print(MENU)
            option = input(">>>").lower()
        elif option == 'd':
            current_taxi.start_fare()
            distance = float(input("Drive how far? "))
            current_taxi.drive(distance)
            print("Your {} trip cost you ${:.2f}".format(current_taxi.name, current_taxi.get_fare()))
            total_bill += current_taxi.get_fare()
            print("Bill to date: ${:.2f}".format(total_bill))
            print(MENU)
            option = input(">>>").lower()
        else:
            print("Invalid option")
            print(MENU)
            option = input(">>>").lower()
    print("Total trip cost: ${:.2f}".format(total_bill))
    print("Taxis are now:")
    display_taxis(taxis)
Example #30
0
def main():
    current_taxi = None
    bill = 0
    taxis = [Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4)]
    print("Let's drive!")
    print(MENU)
    menu_choice = input(PROMPT).lower()
    while menu_choice != 'q':
        if menu_choice == 'c':
            current_taxi = choose_taxi(taxis)
        elif menu_choice == 'd':
            if current_taxi is None:
                print("You haven't chosen a taxi to drive yet!")
            else:
                bill += drive_taxi(current_taxi)
        else:
            print("Invalid Menu Choice")
        print("Bill to date: ${:.2f}".format(bill))
        print(MENU)
        menu_choice = input(PROMPT).lower()
    print("Total trip cost: ${:.2f}".format(bill))
    print("Taxis are now:")
    print_taxis(taxis)