コード例 #1
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 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()
    new_car = Car("fueled", 560)
    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
    # then write the body of the function so that the tests pass
    assert test_car.fuel == 100
    assert new_car.fuel == 560
    test_car = Car(fuel=10)
    assert test_car.fuel == 10
コード例 #2
0
def main():
    """Main."""
    print("Let's Drive")
    car_name = input("Enter your car name: ").title()
    player_car = Car(car_name, 100)
    print(player_car)

    print(MENU)
    menu_selection = input("Enter your choice: ").lower()
    while menu_selection != QUIT:
        if menu_selection == DRIVE:
            distance = get_positive_number(
                "How many km do you wish to drive? ")
            traveled = player_car.drive(distance)
            if traveled < distance:
                warning_string = " and ran out of fuel."
            else:
                warning_string = "."
            print("The car drove {}km{}".format(traveled, warning_string))
        elif menu_selection == REFUEL:
            units_fuel = get_positive_number(
                "How many units of fuel do you want to add to the car? ")
            player_car.add_fuel(units_fuel)
            print("Added {} units of fuel.".format(units_fuel))
        else:
            print("Invalid menu choice, try again.")
        print(player_car)
        print(MENU)
        menu_selection = input(">>>").lower()
    print("Good bye {}'s driver.".format(player_car.name))
コード例 #3
0
def run_tests():
    """Run the tests on the functions."""
    # assert test with no message - used to see if the function works properly
    print(repeat_string("Python", 1))
    assert repeat_string("Python", 1) == "Python"
    # the test below should fail
    print(repeat_string("hi", 2))
    assert repeat_string("hi", 2) == "hi hi"

    # 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"

    assert test_car.fuel == 0, "Car does not set fuel correctly"
    print("good")
    # 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, "Car does not set fuel correctly"
    print("good")
コード例 #4
0
ファイル: used_cars.py プロジェクト: HaydenRobert/Projects
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("{} {}, {}".format(my_car.car_name, my_car.fuel, my_car.odometer))
    print("{self.car_name} {self.fuel}, {self.odometer}".format(self=my_car))
コード例 #5
0
def main():
    my_car = Car(180)
    my_car.drive(30)
    print("fuel =", my_car.fuel)
    print("odo =", my_car.odometer)
    print(my_car)
    limo = Car(100, "limo")
    limo.add_fuel(20)
    print(limo.fuel)
    limo.drive(115)
    print(limo.odometer)
コード例 #6
0
def main():
    """Demo test code to show how to use car class."""
    my_car = Car("WRX", 60)
    my_car.drive(30)
    limo = Car("Limo", 100)
    limo.add_fuel(20)
    limo.drive(115)
    # print("fuel =", my_car.fuel)
    # print("odo =", my_car.odometer)
    print(my_car)
    print(limo.fuel)
コード例 #7
0
def add_fuel(Car):
    amount_of_added_fuel = input(
        "How many units of fuel do you want to add to the car? ")
    valid_input = check_if_integer(amount_of_added_fuel)
    while valid_input is False:
        print("Fuel amount must be >= 0")
        amount_of_added_fuel = input(
            "How many units of fuel do you want to add to the car? ")
        valid_input = check_if_integer(amount_of_added_fuel)

    Car.add_fuel(amount_of_added_fuel)
    print("Added {} units of fuel".format(amount_of_added_fuel))
    print(Car)
コード例 #8
0
def main():
    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), "\n")

    limo = Car(100)
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
コード例 #9
0
ファイル: testing.py プロジェクト: BClark17/Uni-IT-Work
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"

    # 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"
    assert test_car.fuel == 0, "Car does not set default fuel input properly"

    test_car = Car(10)
    assert test_car.fuel == 10, "Car does not set fuel input properly"
コード例 #10
0
ファイル: used_car.py プロジェクト: OwenJMathieson/prac_07
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))

    limo = Car("Limo", 100)
    limo.add_fuel(20)
    print("Limo fuel =", limo.fuel)
    limo.drive(115)
    print("Limo odometer =", limo.odometer)
コード例 #11
0
ファイル: testing.py プロジェクト: nreavell/Pracs
def run_tests():
    assert repeat_string("Python", 1) == "Python"
    assert repeat_string("kwl", 3) == "kwl kwl"

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

    # 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

    test_car = Car()
    assert test_car.fuel == 0
コード例 #12
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))

    my_limo = Limo(100)
    my_limo.add_fuel(20)
    print("fuel =", my_limo.add_fuel)
    Limo.drive(my_limo, 115)
    print("odo =".format(my_limo.drive), my_limo.odometer)
コード例 #13
0
def main():
    """Demo test code to show how to use car class."""
    my_car = 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))
    # Exercise 1
    limo = Car("Limo", 100)
    limo.add_fuel(20)
    print("fuel = {}".format(limo.fuel))
    limo.drive(115)
    print("odo = {}".format(limo.odometer))
    print(limo)
コード例 #14
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)

    # 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())
コード例 #15
0
def main():
    bus = Car(180, 'Bus')
    bus.drive(30)
    print("fuel =", bus.fuel)
    print("odo =", bus.odometer)
    print(bus)
    print(str(bus))

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

    limo = Car(100, 'Limo')
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)

    print(limo)
コード例 #16
0
def main():
    """Demo test code to show how to use car class."""
    my_car = Car(180, "Car")

    limo = Car(100, "Limo")
    limo.add_fuel(20)
    print("limo fuel =", limo.fuel)
    limo.drive(115)
    print("limo odo =", limo.odometer)
    print(limo)

    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))
コード例 #17
0
ファイル: used_cars.py プロジェクト: PeterMenzel/practicals
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("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
    print("{self.name}, fuel={self.fuel}, odometer={self.odometer}".format(
        self=limo))
    print(limo)
コード例 #18
0
def main():
    """Demo guitar_gibson code to show how to use car class."""

    my_car = Car(180, "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("{self.name} {self.fuel}, {self.odometer}".format(self=my_car))

    limo = Car(100, "Limo")
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
    print(limo)
コード例 #19
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))
コード例 #20
0
def main():
    """build a car simulator using car class."""
    print("Let's drive!")
    car_name = ""
    while car_name == "":
        car_name = input("Enter your car name: ")
    car_in_play = Car(car_name, 100)
    menu_selection = ""
    while menu_selection.upper() != QUIT_SELECTED:
        print(car_in_play)
        print(MENU)
        menu_selection = input("Enter your choice: ")
        if menu_selection not in MENU_OPTIONS:
            print("Invalid choice\n")
        elif menu_selection.upper() == DRIVE_SELECTED:
            valid_distance = False
            while not valid_distance:
                try:
                    drive_distance = float(input("How many km do you wish to drive? "))
                    if drive_distance >= 0:
                        print("The car drove {:.0f}km{}.\n".format(car_in_play.drive(drive_distance)
                            , " and ran out of fuel" if car_in_play.fuel == 0 else ""))
                        valid_distance = True
                    else:
                        print("Distance must be >= 0")
                except:
                    print("Invalid distance")
        elif menu_selection.upper() == REFUEL_SELECTED:
            valid_fuel = False
            while not valid_fuel:
                try:
                    fuel_added = float(input("How many units of fuel do you want to add to the car? "))
                    if fuel_added >= 0:
                        print("Added {:.0f} units of fuel.\n".format(car_in_play.add_fuel(fuel_added)))
                        valid_fuel = True
                    else:
                        print("Fuel amount must be >= 0")
                except:
                    print("Invalid fuel amount")
    print("\nGood bye {}'s driver.".format(car_in_play.model_name))
コード例 #21
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"

    # 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

    test_car = Car()
    assert test_car.fuel == 0
コード例 #22
0
def main():
    print("Lets Drive!")
    car_name = input("Enter your car name: ")
    the_bomb = Car(100, car_name)
    print(str(the_bomb))
    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 is_invalid(distance_to_drive):
                print("Distance must be >= 0")
                distance_to_drive = int(
                    input("How many km do you wish to drive? "))
            distance_driven = the_bomb.drive(distance_to_drive)
            print("The car drove {}km".format(distance_driven), end="")
            if the_bomb.fuel == 0:
                print(" and ran out of fuel. ")
        elif choice == "r":
            refuel_amount = int(
                input(
                    "How many units of fuel do you want to add to the car? "))
            while is_invalid(refuel_amount):
                print("Fuel amount must be > = 0")
                refuel_amount = int(
                    input(
                        "How many units of fuel do you want to add to the car? "
                    ))
            the_bomb.add_fuel(refuel_amount)
            print("Added {} units of fuel.".format(refuel_amount))
        else:
            print("Invalid Choice")
        print(str(the_bomb))
        print(MENU)
        choice = input("Enter your choice: ").lower()
    print("Goodbye {}'s driver.".format(car_name))
コード例 #23
0
ファイル: used_cars.py プロジェクト: nreavell/Pracs
def main():
    """Demo test code to show how to use car class."""
    limo = Car("limo", 100)
    limo.add_fuel(20)
    limo.drive(115)
    print(limo)
    print("fuel =", limo.fuel)

    print("{} {}, {}".format(limo.name, limo.fuel, limo.odometer))
    print("{self.name} {self.fuel}, {self.odometer}".format(self=limo))
コード例 #24
0
ファイル: used_cars.py プロジェクト: BelleMardy/all_pracs
def main():
    print(("Car fuel and odometer").upper())
    current_fuel_car = int(input("Current fuel car: >>> "))
    my_car = Car("My car",
                 current_fuel_car)  #  Pascal shows that this is class "Car"
    current_odometer_car = int(input("Current odometer car: >>> "))
    my_car.drive(current_odometer_car)  #  drive is part of the Car class
    print("Car Fuel: {} ".format(my_car.fuel))
    print("Car Odometer: {} ".format(my_car.odometer))
    print("{}".format(my_car))
    print()
    print("-" * 20)
    print()
    print(("Limo fuel and odometer").upper())
    current_fuel_limo = int(input("Current fuel limo: >>> "))
    limo = Car("Limo", current_fuel_limo)
    limo.add_fuel(int(input("Additional fuel: >>> ")))
    current_distance_driven = int(input("Distance driven: >>> "))
    limo.odometer += current_distance_driven
    print("{}".format(limo))
コード例 #25
0
def main():
    hotrod = Car("Hot Rod")

    print(hotrod)
    add_fuel(hotrod)
コード例 #26
0
def main():
    my_car = Car(180)
    my_car.drive(30)
    my_car.name = "Car"
    print("Car Fuel =", my_car.fuel)
    print("Car Odo =", my_car.odometer)
    print(my_car)

    limo = Car(100)
    limo.add_fuel(20)
    print("Limo Fuel:", limo.fuel)
    limo.drive(115)
    print("Limo Odo", limo.odometer)