コード例 #1
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(type, 100)
    print(car)
    print(MENU)
    choice = input("Enter your choice: ").lower()
    while choice != "q":
        if choice == "d":
            distance_to_drive = int(input("How far do you want to go? "))
            while distance_to_drive < 0:
                print("Distance must be >= 0")
                distance_to_drive = int(input("How far do you want to go? "))
            distance_driven = car.drive(distance_to_drive)
            print("The car has driven {}km".format(distance_driven), end="")
            if car.fuel == 0:
                print(" out of fuel", end="")
            print(".")
        elif choice == "r":
            fuel_to_add = int(input("How much fule are you putting in? "))
            while fuel_to_add < 0:
                print("Fuel must be >= 0")
                fuel_to_add = int(input("How much fule are you putting in? "))
            car.add_fuel(fuel_to_add)
            print("Added {} L 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.type))
コード例 #2
0
ファイル: used_cars.py プロジェクト: Dwt2zd/workd
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))
コード例 #3
0
def main():
    my_car = Car("lancer", 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)
    print(limo)
コード例 #4
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)
コード例 #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
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
コード例 #7
0
ファイル: used_cars.py プロジェクト: VuChiKhang/Practical
def main():
    # my_car = Car (180)
    # my_car.drive(30)
    limo=Car(100, "My Limousine")
    limo.add_fuel(20)

    print("fuel = ", limo.fuel)
    limo.drive(115)
    print("odo = ", limo.odometer)
    print(limo)

    print("Car {}, {}".format(limo.fuel, limo.odometer))
    print("Car {self.fuel}, {self.odometer}".format(self=limo))
コード例 #8
0
def main():
    """Demo test code to show how to use car class."""
    # my_car = Car(180) (fuel) is passed into my_car argument
    # my_car.drive(30) (distance) is passed into my_car.drive argument
    limo = Car(100,
               "Limo")  #initialise limo & (fuel) is passed into limo argument
    limo.add_fuel(20)  #added 20 more to fuel
    print("fuel =", limo.fuel)
    limo.drive(115)  #(distance) is passed into limo.drive argument
    print("odo =", limo.odometer)
    print(limo)

    print("Car {}, {}".format(limo.fuel, limo.odometer))
    print("Car {self.fuel}, {self.odometer}".format(self=limo))
コード例 #9
0
ファイル: used_cars.py プロジェクト: Dwt2zd/workd
"""CP1404/CP5632 Practical - Client code to use the Car class."""
# Note that the import has a folder (module) in it.

from prac_6.car import Car


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))


main()
limo = Car("limo", 100)
limo.add_fuel(20)
print("fuel =", limo.fuel)
limo.drive(115)
print("odo =", limo.odometer)
print(limo)
コード例 #10
0
ファイル: used_cars.py プロジェクト: GitGudCoder/CP1404
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)
    print("Limo has {} units of fuel".format(limo.fuel))
    limo.drive(115)
    print("Limo has travelled a total distance of {}km".format(limo.odometer))
    print(limo)

    bus = Car("bus", 200)
    print(bus)