本文整理汇总了Python中car.Car.drive方法的典型用法代码示例。如果您正苦于以下问题:Python Car.drive方法的具体用法?Python Car.drive怎么用?Python Car.drive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类car.Car
的用法示例。
在下文中一共展示了Car.drive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: limo
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def limo():
limo=Car(100,"limo")
limo.add_fuel(20)
print("fuel =", limo.fuel)
limo.drive(115)
print("odo =", limo.odometer)
print(limo)
示例2: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
limo = Car(100, "abc")
limo.add_fuel(20)
print("fuel = ", limo.fuel)
limo.drive(115)
print("odometer = ", limo.odometer)
print(limo)
示例3: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
limo = Car("limo", 180)
limo.add_fuel(30)
limo.drive(115)
print("limo odometer", limo.odometer)
print("limo fuel:", limo.fuel)
print("{}, fuel={}, odometer={}".format(limo.name, limo.fuel, limo.odometer))
示例4: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
bus = Car(180, "Bus")
bus.drive(30)
print(bus)
limo = Car(100,"Limo")
limo.add_fuel(20)
limo.drive(115)
print(limo)
示例5: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
bus = Car("bus",180)
bus.drive(30)
print(bus)
limo = Car("limo", 100)
limo.add_fuel(20)
limo.drive(115)
print(limo)
示例6: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
bus = Car(180)
bus.drive(30)
print("bus fuel =", bus.fuel)
print("bus odo =", bus.odometer)
print(bus)
limbo = Car(100)
limbo.fuel += 20
print("limbo fuel =", limbo.fuel)
limbo.drive(115)
print("limbo obo =", limbo.odometer)
示例7: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
bus = Car("Bus", 180)
bus.drive(30)
print("fuel =", bus.fuel)
print("odo =", bus.odometer)
print(bus)
limo = Car("Limo", 100)
limo.add_fuel(20)
print("fuel =", limo.fuel)
limo.drive(115)
print("odo =", limo.odometer)
示例8: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
# bus = Car(180)
# bus.drive(30)
# print("fuel =", bus.fuel)
# print("odo =", bus.odometer)
# print(bus)
limo = Car(100)
limo.add_fuel(20)
print("limo's fuel = {}".format(limo.fuel))
limo.drive(115)
print("limo's odometer = {}".format(limo.odometer))
示例9: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
bus = Car(180, "bus")
bus.drive(30)
print("fuel =", bus.fuel)
print("odo =", bus.odometer)
print(bus)
limo = Car(100, "limo")
limo.add_fuel(20)
print("fuel=", limo.fuel)
limo.drive(115)
print("odometer=", limo.odometer)
print(limo)
示例10: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
bus = Car(180,'Bus')
bus.drive(30)
print("fuel =", bus.fuel)
print("odo =", bus.odometer)
print(bus)
limo = Car(100,'Limo')
limo.add_fuel(20)
print("fuel =", limo.fuel)
limo.drive(115)
print("odo =", limo.odometer)
print(limo)
示例11: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
bus = Car(180, "Bus")
bus.drive(30)
# print("fuel =", bus.fuel)
# print("odo =", bus.odometer)
print(bus)
limo = Car(100, "Limo")
limo.add_fuel(20)
# print("fuel = ", limo.fuel)
limo.drive(115)
# print("fuel after drive = ", limo.fuel)
# print("odo = ", limo.odometer)
print(limo)
示例12: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
# create an instance of a Car with an initial fuel value of 100
car = Car(100)
print("Let's drive!")
print(car)
print(MENU)
choice = input("Enter your choice: ").lower()
while choice != "q":
if choice == "d":
distanceToDrive = int(input("How many km do you wish to drive? "))
distanceDriven = car.drive(distanceToDrive)
print("The car drove " + str(distanceDriven) + "km", end="")
if car.getFuel() == 0:
print(" and ran out of fuel", end="")
print(".")
elif choice == "r":
fuelToAdd = int(input("How many units of fuel do you want to add to the car? "))
while fuelToAdd < 0:
print("Fuel amount must be >= 0")
fuelToAdd = int(input("How many units of fuel do you want to add to the car? "))
car.addFuel(fuelToAdd)
print("Added", fuelToAdd, "units of fuel.")
else:
print("Invalid choice")
print()
print(car)
print(MENU)
choice = input("Enter your choice: ").lower()
print("\nGood bye!")
示例13: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
bus = Car(100)
bus.drive(40)
print("fuel =", bus.fuel)
print("odo =", bus.odometer)
print(bus)
limo = Car(1500)
limo.add_fuel(20)
print("fuel =", limo.fuel)
print("odo =", limo.odometer)
print(limo)
limo2 = Car(19)
limo2.drive(115)
print("odo =", limo2.odometer)
print(limo2)
示例14: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
bus = Car(180)
bus.drive(30)
print("fuel =", bus.fuel)
print("odo =", bus.odometer)
print(bus)
示例15: main
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import drive [as 别名]
def main():
limo = Car(100)
limo.fuel += 20
limo.drive(115)
print(limo)