예제 #1
0
def main():
    """Demo test code to show how to use car class."""

    my_car = Car(180)
    my_car.drive(30)
    print("fuel =", my_car.fuel)

    print("odo =", my_car.odometer)
    print(my_car)

    print("Car {}, {}".format(my_car.fuel, my_car.odometer))
    print("Car {self.fuel}, {self.odometer}".format(self=my_car))

    limo = Car(100)

    limo.add_fuel(20)

    print("limo fuel after top up ={}".format(limo.fuel))

    limo.drive(115)

    print("limo's odometer now = {}".format(limo.odometer))
    print("limo fuel after driving ={}".format(limo.fuel))

    print(my_car)
    print(limo)
예제 #2
0
def run_tests():
    """Run the tests on the functions."""
    # assert test with no message - used to see if the function works properly
    assert repeat_string("Python", 1) == "Python"
    # the test below should fail
    assert repeat_string("hi", 2) == "hi hi"

    # TODO: 1. fix the repeat_string function above so that it passes the failing test
    # Hint: "-".join(["yo", "yo"] -> "yo-yo"

    # assert test with custom message,
    # used to see if Car's init method sets the odometer correctly
    # this should pass (no output)
    test_car = Car()
    assert test_car.odometer == 0, "Car does not set odometer correctly"

    # TODO: 2. write assert statements to show if Car sets the fuel correctly
    # Note that Car's __init__ function sets the fuel in one of two ways:
    # using the value passed in or the default
    # You should test both of these
    test_car = Car(fuel=10)
    assert test_car.fuel == 10
    # Default car test:
    default_car = Car()
    assert default_car.fuel == 0
예제 #3
0
def main():
    """Demo test code to show how to use car class."""
    my_car = Car(180)
    my_car.drive(30)
    print("fuel =", my_car.fuel)
    print("odo =", my_car.odometer)
    print(my_car)

    print("Car {}, {}".format(my_car.fuel, my_car.odometer))
    print("Car {self.fuel}, {self.odometer}".format(self=my_car))
예제 #4
0
def run_tests():
    assert repeat_string("Python", 1) == "Python"
    assert repeat_string("hi", 2) == "hi hi"

    test_car = Car()
    assert test_car.odometer == 0, "Car does not set odometer correctly"

    test_car = Car(fuel=10)
    assert test_car.fuel == 10

    test_car = Car()
    assert test_car.fuel == 0
예제 #5
0
파일: testing.py 프로젝트: Leylun/Sandbox
def run_tests():
    """Run the tests on the functions."""

    assert repeat_string("Python", 1) == "Python"

    assert repeat_string("hi", 2) == "hi hi"

    test_car = Car()
    assert test_car.odometer == 0, "Car does not set odometer correctly"

    test_car = Car(fuel=10)
    test_car1 = Car()
    assert test_car.fuel == 10, 'Car has incorrect fuel field'
    assert test_car1.fuel == 0, 'Car has incorrect fuel field'
예제 #6
0
def run_tests():
    """Run the tests on the functions."""
    # assert test with no message - used to see if the function works properly
    assert repeat_string("Python", 1) == "Python"
    # the test below should fail
    assert repeat_string("hi", 2) == "hi hi"

    test_car = Car()
    assert test_car.odometer == 0, "Car does not set odometer correctly"

    test_car = Car(fuel=10)
    assert test_car.fuel == 10, "Car does not set fuel correctly"
    test_car = Car()
    assert test_car.fuel == 0, "Car does not set fuel correctly"
예제 #7
0
def main():
    my_car = Car(180, 'Sedan')
    my_car.drive(30)
    print("fuel =", my_car.fuel)
    print("odo =", my_car.odometer)
    print(my_car)

    print('** Limo **')
    limo = Car(100, 'Limo')
    limo.add_fuel(20)
    print('fuel =', limo.fuel)
    limo.drive(115)
    print('odo =', limo.odometer)
    print(limo)
예제 #8
0
def main():
    my_car = Car("My car", 180)
    my_car.drive(30)
    print("fuel =", my_car.fuel)
    print("odo =", my_car.odometer)
    print(my_car)

    print("Car {}, {}".format(my_car.fuel, my_car.odometer))
    print("Car {self.fuel}, {self.odometer}".format(self=my_car))

    limo = Car("Limo", 100)
    limo.add_fuel(20)
    print(limo.fuel)
    limo.drive(115)
    print(limo.odometer)
예제 #9
0
def main():
    """Demo test code to show how to use car class."""
    my_car = Car("My car", 180)
    my_car.drive(30)
    print("fuel =", my_car.fuel)
    print("odo =", my_car.odometer)
    print(my_car)

    print("Car {}, {}".format(my_car.fuel, my_car.odometer))
    print("Car {self.fuel}, {self.odometer}".format(self=my_car))

    limo = Car("Limo", 100)
    limo.add_fuel(20)
    print(limo.fuel)
    limo.drive(115)
    print(limo.odometer)
예제 #10
0
def main():
    """Demo test code to show how to use car class."""
    my_car = Car(180)
    my_car.drive(30)
    print("fuel =", my_car.fuel)
    print("odo =", my_car.odometer)
    print(my_car)

    print("Car {}, {}".format(my_car.fuel, my_car.odometer))
    print("Car, fuel = {self.fuel}, odometer = {self.odometer}".format(
        self=my_car))

    limo = Car(100)
    limo.add_fuel(20)
    print("Limo's fuel = ", limo.fuel)
    limo.drive(115)
    print("limo's odometer reading: ", limo.odometer)
예제 #11
0
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 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())
예제 #13
0
def run_tests():
    """Run the tests on the functions."""
    # assert test with no message - used to see if the function works properly
    assert repeat_string("Python", 1) == "Python"
    # the test below should fail
    assert repeat_string("hi", 2) == "hi hi"

    # TODO: 1. fix the repeat_string function above so that it passes the failing test
    # Hint: "-".join(["yo", "yo"] -> "yo-yo"

    # assert test with custom message,
    # used to see if Car's init method sets the odometer correctly
    # this should pass (no output)

    test_car_1 = Car("Huy", 20)
    test_car_2 = Car("Nhan")
    assert test_car_1.odometer == 0, "Car does not set odometer correctly"
    assert test_car_2.fuel == 100, "Car does not set odometer correctly"
예제 #14
0
def run_tests():
    """Run the tests on the functions."""
    # assert test with no message - used to see if the function works properly
    assert repeat_string("Python", 1) == "Python"
    # the test below should fail
    assert repeat_string("hi", 2) == "hi hi"

    # assert test with custom message,
    # used to see if Car's init method sets the odometer correctly
    # this should pass (no output)
    test_car = Car()
    assert test_car.odometer == 0, "Car does not set odometer correctly"

    # Note that Car's __init__ function sets the fuel in one of two ways:
    # using the value passed in or the default
    # You should test both of these
    test_car = Car(fuel=10)
    assert test_car.fuel == 10
    test_car_1 = Car()
    assert test_car_1.fuel == 0
예제 #15
0
def main():
    """Car simulator program, demonstrating use of Car class."""
    print("Let's drive!")
    name = input("Enter your car name: ")
    # create a Car instance with initial fuel of 100 and user-provided name
    car = Car(name, 100)
    print(car)
    print(MENU)
    choice = input("Enter your choice: ").lower()
    while choice != "q":
        if choice == "d":
            distance_to_drive = int(
                input("How many km do you wish to drive? "))
            while distance_to_drive < 0:
                print("Distance must be >= 0")
                distance_to_drive = int(
                    input("How many km do you wish to drive? "))
            distance_driven = car.drive(distance_to_drive)
            print("The car drove {}km".format(distance_driven), end="")
            if car.fuel == 0:
                print(" and ran out of fuel", end="")
            print(".")
        elif choice == "r":
            fuel_to_add = int(
                input(
                    "How many units of fuel do you want to add to the car? "))
            while fuel_to_add < 0:
                print("Fuel amount must be >= 0")
                fuel_to_add = int(
                    input(
                        "How many units of fuel do you want to add to the car? "
                    ))
            car.add_fuel(fuel_to_add)
            print("Added {} units of fuel.".format(fuel_to_add))
        else:
            print("Invalid choice")
        print()
        print(car)
        print(MENU)
        choice = input("Enter your choice: ").lower()
    print("\nGood bye {}'s driver.".format(car.name))
예제 #16
0
def run_tests():
    """Run the tests on the functions."""
    # assert test with no message - used to see if the function works properly
    assert repeat_string("Python", 1) == "Python"
    # the test below should fail
    assert repeat_string("hi", 2) == "hi hi"

    # TODO: 1. fix the repeat_string function above so that it passes the failing test
    # Hint: "-".join(["yo", "yo"] -> "yo-yo"

    # assert test with custom message,
    # used to see if Car's init method sets the odometer correctly
    # this should pass (no output)
    test_car = Car()
    assert test_car.odometer == 0, "Car does not set odometer correctly"

    test_car = Car(fuel=10)
    assert test_car.fuel == 10
    test_car = Car()
    assert test_car.fuel == 0

    assert automatic_sentence('It is an ex parrot.')
예제 #17
0
def main():
    print("Let's drive!")
    name = input("Enter your car name: ")
    car = Car(name, 100)
    print(car)
    print(MENU)
    choice = input("Enter your choice: ").lower()
    while choice != "q":
        if choice == "d":
            distance_to_drive = int(
                input("How many km do you wish to drive? "))
            while distance_to_drive < 0:
                print("Distance must be >= 0")
                distance_to_drive = int(
                    input("How many km do you wish to drive? "))
            distance_driven = car.drive(distance_to_drive)
            print("The car drove {}km".format(distance_driven), end="")
            if car.fuel == 0:
                print(" and ran out of fuel", end="")
            print(".")
        elif choice == "r":
            fuel_to_add = int(
                input(
                    "How many units of fuel do you want to add to the car? "))
            while fuel_to_add < 0:
                print("Fuel amount must be >= 0")
                fuel_to_add = int(
                    input(
                        "How many units of fuel do you want to add to the car? "
                    ))
            car.add_fuel(fuel_to_add)
            print("Added {} units of fuel.".format(fuel_to_add))
        else:
            print("Invalid choice")
        print()
        print(car)
        print(MENU)
        choice = input("Enter your choice: ").lower()
    print("Good bye {}'s driver.".format(car.name))
예제 #18
0
def main():
    """Simulate driving of car object"""

    print("Lets Drive!")
    car_name = get_name()
    my_car = Car(car_name, STARTING_FUEL)
    menu_choice = str(display_menu()).lower()

    while menu_choice != "q":

        if menu_choice == "d":
            print("How many km's do you wish to drive? ")
            drive_distance = get_int_entry()
            if my_car.fuel - drive_distance > 0:
                print("Your car drove {} kms ".format(drive_distance))
                my_car.odometer = my_car.odometer + drive_distance
                my_car.fuel = my_car.fuel - drive_distance
                print("Your car has travelled {} kms today".format(
                    my_car.odometer))

            else:
                print("Your car doesn't have enough fuel!")

            print(my_car)
            menu_choice = display_menu()

        elif menu_choice == "r":
            print("How many units of fuel do you wish to add to the car? ")
            amount_to_refuel = get_int_entry()

            print("Added {} units to the car".format(amount_to_refuel))
            print(my_car)
            menu_choice = display_menu()

        else:
            print("Invalid menu choice, please try again.")
            menu_choice = display_menu()

    print("Good by the {} 's driver! ".format(my_car.name))
예제 #19
0
def main():
    """Demo test code to show how to use car class."""
    my_car = Car(180, 'My car')
    my_car.drive(30)
    print("fuel =", my_car.fuel)
    print("odo =", my_car.odometer)
    print(my_car)

    print("{} {}, {}".format(my_car.name,my_car.fuel, my_car.odometer))
    print("Car {self.fuel}, {self.odometer}".format(self=my_car))

    #1. create new car object called limo and set the fuel to 100
    limo = Car(100,'limo')
    #2. add 20 more units of fuel to this new car object using the add method
    limo.add_fuel(20)
    #3. print the amount of fuel in the limo car
    print('limo fuel = ',limo.fuel)
    #4. attempt to drvie 115km
    limo.drive(115)
    #5. print the car's odometer reading
    print('limo odometer = ',limo.odometer)
    print(limo)
예제 #20
0
파일: used_cars.py 프로젝트: Leylun/Sandbox
def main():
    """Demo test code to show how to use car class."""
    limo = Car(100, "Limo")
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
    print(limo)
예제 #21
0
def main():
    # """Demo test code to show how to use car class."""
    # my_car = Car(180)
    # my_car.drive(30)
    # print("fuel =", my_car.fuel)
    # print("odo =", my_car.odometer)
    # print(my_car)
    #
    # print("Car {}, {}".format(my_car.fuel, my_car.odometer))
    # print("Car {self.fuel}, {self.odometer}".format(self=my_car))

    limo = Car("limo", 100)
    limo.add_fuel(20)
    limo.drive(115)

    print(limo.fuel)
    print(limo.odometer)
    print(limo.specs())
예제 #22
0
def main():
    print("Let's drive!")
    my_car = Car(input("Enter your car name: "), 100)
    print("{}, fuel={}, odo={}".format(my_car.name, my_car.fuel,
                                       my_car.odometer))
    print(MENU)

    choice = input(">>> ").upper()
    while choice != "Q":
        if choice == "D":
            drive_car(my_car)
        elif choice == "R":
            refuel_car(my_car)
        else:
            print("Invalid menu choice")
        print()
        print(my_car)
        print(MENU)
        choice = input(">>> ").upper()
    print("Goodbye {}'s owner".format(my_car.name))
예제 #23
0
def main():
    """Demo test code to show how to use car class."""

    # 1. limo = Car(100)
    limo = Car("Limo", 100)  # 7. updated with name
    # 2.
    limo.add_fuel(20)
    # 3.
    print("Limo fuel =", limo.fuel)
    # 4.
    limo.drive(115)
    # 5.
    print("Limo odo =", limo.odometer)
    # 6.
    print(limo)
예제 #24
0
def main():
    print("Let's drive!")
    car_name = str(input("Enter your car name"))
    my_car = Car(car_name)
    print("{}, fuel = {}, odo = {}".format(my_car.name, my_car.fuel,
                                           my_car.odometer))
    menu_choice = insert_menu()
    while menu_choice.lower() == "d" or menu_choice.lower() == "r":

        if menu_choice.lower() == "d":
            while True:
                try:
                    distance = float(input("how many km you want to drive? "))
                    while distance < 0:
                        print("the distance must be >=0")
                        distance = float(
                            input("how many km you want to drive? "))

                    break
                except ValueError:
                    print("Invalid Input Value")
            my_car.drive(distance)
            print("{}, fuel = {}, odo = {}".format(my_car.name, my_car.fuel,
                                                   my_car.odometer))
            menu_choice = insert_menu()
        else:
            while True:
                try:
                    amount = float(
                        input(
                            "How many units of fuel do you want to add to the car? "
                        ))
                    while amount < 0:
                        print("Fuel amount must be >= 0")
                        amount = float(
                            input(
                                "How many units of fuel do you want to add to the car? "
                            ))

                    break
                except ValueError:
                    print("Invalid Input Value")
            my_car.add_fuel(amount)
            print("{}, fuel = {}, odo = {}".format(my_car.name, my_car.fuel,
                                                   my_car.odometer))
            menu_choice = insert_menu()
from Prac_06.car import Car

VALID_USER_CHOICES = ['d', 'r', 'q']

print("Let's drive!")

name = input('Enter you car name: ')
user_choice = None
distance_in_km = -1
units_of_fuel = -1
car = Car(fuel=100, name=name)

while user_choice != 'q':
    print(car)

    print("""
    Menu:
    d) drive
    r) refuel
    q) quit
    """)
    user_choice = input('Enter your choice: ').lower()

    if user_choice not in VALID_USER_CHOICES:
        print('Invalid choice')
    else:
        if user_choice == 'd':
            while distance_in_km < 0:
                distance_in_km = int(
                    input('How many km do you wish to drive? '))