def dealership_init(): red_car = Car() print('Colour ' + red_car.getColour()) print('Mileage ' + str(red_car.getMileage())) print('Make ' + red_car.getMake()) red_car.setMake('Ferrari') print('Make ' + red_car.getMake()) print('Getting a paint job - the new colour is ' + red_car.paint('red')) print('Colour ' + red_car.getColour()) print('Car moved' + str(red_car.move(15)) + 'kms') print('Mileage ' + str(red_car.getMileage())) print('Engine Size ' + red_car.engineSize) red_car.engineSize = '3.9' print('Engine Size ' + red_car.engineSize) car3 = ElectricCar() car3.setColour('white') car3.setMileage(500) car3.setNumberFuelCells(2) car3.move(20) print('Colour ' + car3.getColour()) print('Number of fuel cells ' + str(car3.getNumberFuelCells()))
def prob_9_9(): my_ecar = ElectricCar('tesla', 'model s', 2019, 75) print(f"|{my_ecar.longname()}|") my_ecar.update_odometer(123) my_ecar.print_odometer() my_ecar.battery.upgrade_battery() print(f"|{my_ecar.longname()}|")
def test_electric_car_charge(): ec = ElectricCar(100) assert ec.drive(70) == 70 assert ec.drive(50) == 30 assert ec.drive(50) == 0 ec.charge() assert ec.drive(50) == 50
def setUp(self): self.car = Car() self.car1 = ElectricCar(1) self.car2 = PetrolCar(2) self.car3 = DieselCar(3) self.car4 = HybridCar(4) self.dealership = Dealership() self.dealership.create_current_stock()
def create_current_stock(self): for i in range(24): self.petrol_cars.append(PetrolCar()) for i in range(8): self.diesel_cars.append(DieselCar()) for i in range(4): self.electric_cars.append(ElectricCar()) for i in range(4): self.hybrids.append(HybridCar())
def create_current_fleet(self): for i in range(6): self.electric_cars.append(ElectricCar()) for i in range(20): self.petrol_cars.append(PetrolCar()) for i in range(10): self.diesel_cars.append(DieselCar()) for i in range(4): self.hybrid_cars.append(HybridCar())
def process_rental(self): answer = str.lower(raw_input(' Would you like to rent a car? Yes: "Y", No: "N" : ')) if answer == 'y': answer = str.lower(raw_input(' Choose "p" for Petrol, "d" for Diesel, "e" for electric and "h" for Hybrid: ')) amount = int(raw_input(' How many would you like? ')) if answer == 'p': self.rent(self.petrol_cars, amount) choice = raw_input(' Write the model you would like: Toyota, Kia, Volkswagon, Ford: ') petrol_car = PetrolCar() petrol_car.setMake(choice) mileage = int(raw_input(' Record the mileage here before you start driving. ')) petrol_car.setMileage(mileage) print 'Your car is: ', petrol_car.getMake() print 'The current mileage is set at: ', petrol_car.getMileage() return mileage elif answer == 'd': self.rent(self.diesel_cars, amount) choice = raw_input(' Write the model you would like: Nissan or Hyundai: ') diesel_car = DieselCar() diesel_car.setMake(choice) mileage = int(raw_input(' Record the mileage here before you start driving. ')) diesel_car.setMileage(mileage) print 'Your car is: ', diesel_car.getMake() print 'The current mileage is set at: ', diesel_car.getMileage() return mileage elif answer == 'e': self.rent(self.electric_cars, amount) choice = raw_input(' We have a Nissan or a Tesla, please write your choice: ') electric_car = ElectricCar() electric_car.setMake(choice) mileage = int(raw_input(' Record your mileage here before you start driving. ')) electric_car.setMileage(mileage) print 'Your model is', electric_car.getMake() print 'Fuel cells available are', electric_car.getNumberFuelCells() print 'Your current mileage is set to: ', electric_car.getMileage() return mileage else: self.rent(self.hybrid_cars, amount) choice = raw_input(' what hybrid do you want, Prius or Lexus? ') hybrid_car = HybridCar() hybrid_car.setMake(choice) mileage = int(raw_input(' Record your mileage here before you start driving. ')) hybrid_car.setMileage(mileage) print 'Your model is', hybrid_car.getMake() print 'Our hybrid cars come with :', hybrid_car.getNumberFuelCells(), 'fuel cells and ', hybrid_car.getNumberCylinders(), 'cylinders ' print 'Your current mileage is set to: ', hybrid_car.getMileage() return mileage car_fleet = CarFleet() car_fleet.rentCar(amount) if answer == 'n': self.process_returnCar() self.stock_count()
def test_electric_car(self): car = ElectricCar('Volksvagen', 'Passat', 'White', '01 P 1234', 2) self.assertEqual(car.get_make(), 'Volksvagen') self.assertEqual(car.get_model(), 'Passat') self.assertEqual(car.get_colour(), 'White') self.assertEqual(car.get_registration(), '01 P 1234') self.assertEqual(car.get_number_fuel_cells(), 2) self.assertEqual(car.get_is_rented(), False) self.assertEqual( str(car), 'Electric,Volksvagen,Passat,White,01 P 1234,False,,2,\n')
def main(): my_tesla = ElectricCar('tesla', 'model s', 2016) print(my_tesla.get_descriptive_name()) my_tesla.battery.describe_battery() my_tesla.battery.get_range() my_tesla.battery.upgrade_battery() my_tesla.battery.get_range() """导入整个模块,使用语法module_name.class_name访问需要的类""" my_beetle = car.Car('volkswagen', 'beetle', 2016) print(my_beetle.get_descriptive_name())
def __init__(self): self.__petrol_cars = [] self.__diesel_cars = [] self.__electric_cars = [] self.__hybrid_cars = [] self.__csv_header = '' for i in range(1, 21): self.__petrol_cars.append(PetrolCar()) for i in range(1, 11): self.__diesel_cars.append(DieselCar()) for i in range(1, 7): self.__electric_cars.append(ElectricCar()) for i in range(1, 5): self.__hybrid_cars.append(HybridCar())
def create_current_stock(self, typecar, start): #set up the initial stock for each type of cars # it has been called in the main (row 100) if typecar == 'E': for i in range(start): self.electric_cars.append(ElectricCar()) elif typecar == 'P': for i in range(start): self.petrol_cars.append(PetrolCar()) elif typecar == 'D': for i in range(start): self.diesel_cars.append(DieselCar()) elif typecar == 'H': for i in range(start): self.hybrid_cars.append(HybridCar())
def create_current_stock(self): self.overallTotal = 40 # total stock the dealer plans on having initially uniqueID = 100 # each car will have it's own unique ID, this is the starting integer # Making an assumption here that the dealer will maintain the current # ratio of 50% petrol, 20% diesel, 10% electric and 20% hybrid # this could be changed to fixed qtys of each # 'build' the fleet! for i in range(int(self.overallTotal * 0.5)): self.petrol_cars.append(PetrolCar(uniqueID)) uniqueID += 1 for i in range(int(self.overallTotal * 0.2)): self.diesel_cars.append(DieselCar(uniqueID)) uniqueID += 1 for i in range(int(self.overallTotal * 0.2)): self.hybrid_cars.append(HybridCar(uniqueID)) uniqueID += 1 for i in range(int(self.overallTotal * 0.1)): self.electric_cars.append(ElectricCar(uniqueID)) uniqueID += 1
def test_car_rental_set_methods(self): self.carRental.setFleet(40) self.assertEquals(40, self.carRental.getFleet()) petrolCar = PetrolCar() dieselCar = DieselCar() electricCar = ElectricCar() hybridCar = HybridCar() self.carRental.setAvailablePetrolCars([petrolCar, petrolCar]) self.assertEquals([petrolCar, petrolCar], self.carRental.getAvailablePetrolCars()) self.carRental.setAvailableDieselCars( [dieselCar, dieselCar, dieselCar]) self.assertEquals([dieselCar, dieselCar, dieselCar], self.carRental.getAvailableDieselCars()) self.carRental.setAvailableElectricCars([electricCar, electricCar]) self.assertEquals([electricCar, electricCar], self.carRental.getAvailableElectricCars()) self.carRental.setAvailableHybridCars([hybridCar, hybridCar]) self.assertEquals([hybridCar, hybridCar], self.carRental.getAvailableHybridCars())
def returnCar(self, carType): # checks car type if carType == 'Petrol': # call checkRentals function to determine whether or not the car type is on rentals index = self.checkRentals('Petrol') # if car type is in rentals then remove it from rentals and add it to the associated array if index != -1: self.rental_cars.pop(index) self.petrol_cars.append(PetrolCar()) return 'You have returned the car' # else car type is not in rentals else: return 'No petrol cars currently on rental' elif carType == 'Diesel': index = self.checkRentals('Diesel') if index != -1: self.rental_cars.pop(index) self.petrol_cars.append(DieselCar()) return 'You have returned the car' else: return 'No diesel cars currently on rental' elif carType == 'Electric': index = self.checkRentals('Electric') if index != -1: self.rental_cars.pop(index) self.petrol_cars.append(ElectricCar()) return 'You have returned the car' else: return 'No electric cars currently on rental' elif carType == 'Hybrid': index = self.checkRentals('Hybrid') if index != -1: self.rental_cars.pop(index) self.petrol_cars.append(HybridCar()) return 'You have returned the car' else: return 'No hybrids currently on rental'
red_car.setMake('Ferrari') print 'Make ' + red_car.getMake() print('Getting a paint job - the new colour is ' + red_car.paint('red')) print 'Colour ' + red_car.getColour() print('Car moved' + str(red_car.move(15)) + 'kms') print 'Mileage ' + str(red_car.getMileage()) print 'Engine Size ' + red_car.engineSize red_car.engineSize = '3.9' print 'Engine Size ' + red_car.engineSize car3 = ElectricCar() car3.setColour('white') car3.setMileage(500) car3.setNumberFuelCells(2) car3.move(20) print 'Colour ' + car3.getColour() print 'Number of fuel cells ' + str(car3.getNumberFuelCells()) class Dealership(object): def __init__(self): self.electric_cars = [] self.petrol_cars = [] def create_current_stock(self): for i in range(20):
# print(my_tesla.get_descriptive_name()) # my_tesla.battery.describe_battery() # my_tesla.battery.get_range() # 大部分逻辑被隐藏再一个模块中 # 9.4.3 从一个模块中导入多个类 print("\n9.4.3") from car import Car, ElectricCar # ,号分隔 my_beetle = Car('a', 'beetle', 2017) # Car类 print(my_beetle.get_descriptive_name()) my_tesla = ElectricCar('tesla', 'roadster', 2018) # ElectricCar类 print(my_tesla.get_descriptive_name()) # 9.4.4 导入整个模块 print("\n9.4.4") import car # 导入整个car模块 one = car.Car('one', 'one', 2010) # 模块.类 print(one.get_descriptive_name()) two = car.ElectricCar('two', 'two', 2020) # 模块.类 print(two.get_descriptive_name()) # 9.4.5 导入模块中的所有类 print("\n9.4.5") #from car import * # 不推荐这种导入方式
def setUp(self): TestCar.setUp(self) self.electricCar = ElectricCar()
from car import Car, ElectricCar #from car import * my_beetle = Car('Volks', 'beetle', 2016) print(my_beetle.get_descriptive_name()) print('\n') my_tesla = ElectricCar('tesla', 'model s', 2016) print(my_tesla.get_descriptive_name()) my_tesla.battery.describe_battery() my_tesla.fill_gas_thank() my_tesla.battery.get_range() print('\n') other_tesla = ElectricCar('tesla', 'model s', 2020) print(other_tesla.get_descriptive_name()) other_tesla.battery.describe_battery() other_tesla.battery.get_range() other_tesla.battery.upgrade_battery() other_tesla.battery.get_range()
#Dushyant Tara(21-06-2020):This program helps you import classes from modules from car import Car, ElectricCar #or import the whole module using #import car then use car.Car or car.ElectricCar syntax my_beetle = Car('volkswagen','beetle',2016) print(my_beetle.get_descriptive_name()) my_tesla = ElectricCar('tesla','roadster',2016) print(my_tesla.get_descriptive_name())
#print my_car.__colour #Will not print "same reason in line 27 print my_car.getMileage() #print my_car.__mileage #Will not print "same reason in line 27 my_car.engineSize = ("2.5L") print my_car.engineSize my_car.setMake("BMW") print my_car.getMake() my_car.setColour("Silver") print my_car.getColour() my_car.setMileage(50) print my_car.getMileage() my_car.move(10) print my_car.getMileage() my_car.paint("Blue") print my_car.getColour() electric_car = ElectricCar() #Class ElectricCar or electric_car print electric_car.getNumberFuelCells() electric_car.move(20) print electric_car.getMileage() #my_car.getNumberFuelCells() #error bc my_car does not have NumberofFuels
from car import ElectricCar my_tesla = ElectricCar ('tesla', 's', 2016) print(my_tesla.get_descriptive_name()) my_tesla.battery.describe_battery() my_tesla.battery.get_range()
def create_current_stock(self): for i in range(20): self.electric_cars.append(ElectricCar()) for i in range(10): self.petrol_cars.append(PetrolCar())
from car import ElectricCar my_tesla = ElectricCar('tesla', 'model a', 2020) print(my_tesla.get_descriptive_name()) my_tesla.battery.describe_battery() my_tesla.battery.get_range()
class CarRentalApp(object): ## create car objects global car, engineCar, petrolCar, dieselCar, electricCar, hybridCar, carRental car = Car() engineCar = EngineCar() petrolCar = PetrolCar() dieselCar = DieselCar() electricCar = ElectricCar() hybridCar = HybridCar() carRental = CarRental() ## create customer object global customer customer = Customer() def fleetInfo(): ## construct car fleet carRental.setFleet(40) fleet = carRental.getFleet() availablePetrol = int(0.60 * fleet) availableDiesel = int(0.20 * fleet) availableElectric = int(0.10 * fleet) availableHybrid = int(0.10 * fleet) carRental.setAvailablePetrolCars([]) carRental.setAvailableDieselCars([]) carRental.setAvailableElectricCars([]) carRental.setAvailableHybridCars([]) for p in range(1, availablePetrol + 1): carRental.availablePetrolCars.append(petrolCar) for d in range(1, availableDiesel + 1): carRental.availableDieselCars.append(dieselCar) for e in range(1, availableElectric + 1): carRental.availableElectricCars.append(electricCar) for h in range(1, availableHybrid + 1): carRental.availableHybridCars.append(hybridCar) def customerDetails(): ## print quit message print('Type "q" to quit this program') ## obtain input form user while True: name = input('Please enter Customer name: ') if name == 'q' or name == 'Q': quit() ## check user did not just press return button ## and all characters are alphabetic ## note: unfortunately the isalpha method will not work in cases ## whereby some african names contain an exclamation mark if name.isalpha() == False: print('Sorry, name not recognised. Please try again.') continue customer.setName(name) licence = input('Please enter Customer driving licence number: ') if licence == 'q' or customer.licence == 'Q': quit() if licence == '': print('Sorry, licence not valid. Please try again.') continue customer.setLicence(licence) print('Type "H" if Customer wishes to hire a car from the fleet.') print('Type "R" if Customer is returning a car to the fleet.') global hireReturn hireReturn = input('Hire or Return?: ') if hireReturn == 'q': quit() hireReturn = hireReturn.lower() if (hireReturn != 'h') and (hireReturn != 'r'): print('Invalid input. Please try again.') continue break return hireReturn def carInfo(): ## obtain car choice while True: print('What type of car is being hired/returned?:') print('Type "P" for petrol') print('Type "D" for diesel') print('Type "E" for electric') print('Type "H" for hybrid') global carChoice carChoice = input('Enter car type now: ') carChoice = carChoice.lower() if carChoice == 'q': quit() carChoiceOptions = ['p', 'd', 'e', 'h'] ## check for valid carChoice if carChoice not in carChoiceOptions: print('Invalid car choice. Please try agsin.') continue ## check if car choice available if hireReturn == 'h': if ( (carChoice == 'p') and (len(carRental.getAvailablePetrolCars()) <= 0) ) \ or ( (carChoice == 'd') and (len(carRental.getAvailableDieselCars()) <= 0) ) \ or ( (carChoice == 'e') and (len(carRental.getAvailableElectricCars()) <= 0) ) \ or ( (carChoice == 'h') and (len(carRental.getAvailableHybridCars()) <= 0) ): print( 'Apologies, there are none of this car type currently in the fleet.' ) print('Please choose alternative car type.') continue break return carChoice def transmissionInfo(): ##obtain transmission info while True: if hireReturn == 'h': print( 'Does Customer prefer an Automatic or a Manual transmission?:' ) print('Type "A" for Automatic') print('Type "M" for Manual') transmissionChoice = input('Enter transmission preference: ') transmissionChoice = transmissionChoice.lower() if transmissionChoice == 'q': quit() transmissionChoiceOptions = ['a', 'm'] ## check for valid transmissionChoice if transmissionChoice not in transmissionChoiceOptions: print('Invalid transmission choice. Please try agsin.') continue if transmissionChoice == 'a': engineCar.setTransmission('Automatic') if transmissionChoice == 'm': engineCar.setTransmission('Manual') break def carMakeInfo(): ##obtain car make info while True: if hireReturn == 'h': print('Does Customer prefer a Ford or a Toyota?:') print('Type "F" for Ford') print('Type "T" for Toyota') makeChoice = input('Enter Make preference: ') makeChoice = makeChoice.lower() if makeChoice == 'q': quit() makeChoiceOptions = ['f', 't'] ## check for valid makeChoice if makeChoice not in makeChoiceOptions: print('Invalid Make choice. Please try agsin.') continue if makeChoice == 'f': car.setMake('Ford') if makeChoice == 't': car.setMake('Toyota') break def carModelInfo(): ##obtain car model info while True: if car.getMake() == 'Ford': print('Does Customer prefer a Focus or a Mondeo?:') print('Type "F" for Focus') print('Type "M" for Mondeo') modelChoice = input('Enter Model preference: ') modelChoice = modelChoice.lower() if modelChoice == 'q': quit() modelChoiceOptions = ['f', 'm'] ## check for valid modelChoice if modelChoice not in modelChoiceOptions: print('Invalid Model choice. Please try agsin.') continue if modelChoice == 'f': car.setModel('Focus') if modelChoice == 'm': car.setModel('Mondeo') break while True: if car.getMake() == 'Toyota': print('Does Customer prefer a Corolla or an Avensis?:') print('Type "C" for Corolla') print('Type "A" for Avensis') modelChoice = input('Enter Model preference: ') modelChoice = modelChoice.lower() if modelChoice == 'q': quit() modelChoiceOptions = ['c', 'a'] ## check for valid modelChoice if modelChoice not in modelChoiceOptions: print('Invalid make choice. Please try agsin.') continue if modelChoice == 'c': car.setModel('Corolla') if modelChoice == 'a': car.setModel('Avensis') break def petrolCarInfo(): ##obtain fuel info while True: if carChoice == 'p': print('Does Customer have a fuel preference?:') print('Type "L" for leaded') print('Type "U" for unleaded') fuelChoice = input('Enter Customer choice now: ') fuelChoice = fuelChoice.lower() if fuelChoice == 'q': quit() fuelChoiceOptions = ['l', 'u'] ## check for valid fuelChoice if fuelChoice not in fuelChoiceOptions: print('Invalid fuel choice. Please try agsin.') continue if fuelChoice == 'l': petrolCar.setPetrolType('Leaded') if fuelChoice == 'u': petrolCar.setPetrolType('Unleaded') break def dieselCarInfo(): ##obtain turbo info while True: if carChoice == 'd': print('Does Customer prefer standard or turbo?:') print('Type "S" for standard') print('Type "T" for turbo') turboChoice = input('Enter Customer choice now: ') turboChoice = turboChoice.lower() if turboChoice == 'q': quit() turboChoiceOptions = ['s', 't'] ## check for valid turboChoice if turboChoice not in turboChoiceOptions: print('Invalid turbo choice. Please try agsin.') continue if turboChoice == 's': dieselCar.setDieselTurbo(False) if turboChoice == 't': dieselCar.setDieselTurbo(True) break def electricCarInfo(): ##obtain fuelCells info while True: if carChoice == 'e': print('Does Customer prefer battery or capacitor?:') print('Type "B" for battery') print('Type "C" for capacitor') fuelCellsChoice = input('Enter Customer choice now: ') fuelCellsChoice = fuelCellsChoice.lower() if fuelCellsChoice == 'q': quit() fuelCellsChoiceOptions = ['b', 'c'] ## check for valid fuelCellsChoice if fuelCellsChoice not in fuelCellsChoiceOptions: print('Invalid fuel cell choice. Please try agsin.') continue if fuelCellsChoice == 'b': electricCar.setFuelCells('Battery') if fuelCellsChoice == 'c': electricCar.setFuelCells('Capacitor') break def hybridCarInfo(): ##obtain brake info while True: if carChoice == 'h': print( 'Does Customer prefer standard or regenerative braking system?:' ) print('Type "S" for standard brake system') print('Type "R" for regenerative brake system') brakeChoice = input('Enter Customer choice now: ') brakeChoice = brakeChoice.lower() if brakeChoice == 'q': quit() brakeChoiceOptions = ['s', 'r'] ## check for valid brakeChoice if brakeChoice not in brakeChoiceOptions: print('Invalid brake choice. Please try agsin.') continue if brakeChoice == 's': hybridCar.setHybridBrake(False) if brakeChoice == 'r': hybridCar.setHybridBrake(True) break def updateFleet(carChoice, hireReturn): ## remove/add one (1) car to/from fleet fleet = carRental.getFleet() if carChoice == 'p': if (hireReturn == 'h'): carRental.availablePetrolCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availablePetrolCars.append(petrolCar) fleet += 1 else: print('Hell has just frozen over. Petrol debug necessary!') quit() elif carChoice == 'd': if (hireReturn == 'h'): carRental.availableDieselCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availableDieselCars.append(dieselCar) fleet += 1 else: print('Hell has just frozen over. Diesel debug necessary!') quit() elif carChoice == 'e': if (hireReturn == 'h'): carRental.availableElectricCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availableElectricCars.append(electricCar) fleet += 1 else: print('Hell has just frozen over. Electric debug necessary!') quit() elif carChoice == 'h': if (hireReturn == 'h'): carRental.availableHybridCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availableHybridCars.append(hybridCar) fleet += 1 else: print('Hell has just frozen over. Hybrid debug necessary!') quit() else: print('Woah ... back up the apple-cart. Debug required now!') quit() def calculateHirePeriod(hireReturn): while True: print('How many days does Customer require?') print('Number must be between 1 and 28 (inclusive).') hirePeriod = input('Please enter number of days: ') if hirePeriod == 'q': quit() try: hirePeriod = int(hirePeriod) if (1 <= hirePeriod) and (hirePeriod <= 28): break else: print('Hire period must be between 1 and 28.') except: print("Invalid input. Try again.") return hirePeriod def calculateHireCharge(hireReturn, hirePeriod): ## hire rates for large cars (i.e. Avensis & Mondeo): ## are 50 euro per day for the first 10 days ## and 35 euro per day thereafter ## hire rates for small cars (i.e. Corolla & Focus): ## are 40 euro per day for the first 10 days ## and 25 euro per day thereafter if hirePeriod <= 10: if (car.getModel() == 'Avensis') or (car.getModel() == 'Mondeo'): hireCharge = hirePeriod * 50.00 if (car.getModel() == 'Corolla') or (car.getModel() == 'Focus'): hireCharge = hirePeriod * 40.00 elif (10 < hirePeriod) and (hirePeriod <= 28): if (car.getModel() == 'Avensis') or (car.getModel() == 'Mondeo'): hireCharge = 500 + ((hirePeriod - 10) * 35.00) if (car.getModel() == 'Corolla') or (car.getModel() == 'Focus'): hireCharge = 400 + ((hirePeriod - 10) * 25.00) else: print("Oops! ... we shouldn't be here!") quit() return hireCharge fleetInfo() hireReturn = customerDetails() carInfo() transmissionInfo() carMakeInfo() carModelInfo() petrolCarInfo() dieselCarInfo() electricCarInfo() hybridCarInfo() availableCars = updateFleet(carChoice, hireReturn) if hireReturn == 'h': customer.hirePeriod = calculateHirePeriod(hireReturn) customer.hireCharge = calculateHireCharge(hireReturn, customer.hirePeriod) print('Customer name:\t\t\t', customer.getName()) print('Customer licence:\t\t', customer.getLicence()) if hireReturn == 'r': print('Thanks for returning the car.') print('Hope to see you again soom.') if hireReturn == 'h': print('Make of car hired:\t\t', car.getMake()) print('Model of car hired:\t\t', car.getModel()) print('Transmission of car hired:\t', engineCar.getTransmission()) if carChoice == 'p': print('Petrol type:\t\t\t', petrolCar.getPetrolType()) if carChoice == 'd': print('Has turbo?:\t\t\t', dieselCar.getDieselTurbo()) if carChoice == 'e': print('Fuel cell type:\t\t\t', electricCar.getFuelCells()) if carChoice == 'h': print('Regenerative braking system:\t', hybridCar.getHybridBrake()) print('Hire period (days):\t\t', customer.hirePeriod) print('Hire charge (euro):\t\t', customer.hireCharge)
def test_electric_car_fuel_cells(self): electric_car = ElectricCar() self.assertEqual(1, electric_car.getNumberFuelCells()) electric_car.setNumberFuelCells(4) self.assertEqual(4, electric_car.getNumberFuelCells())
from car import Car, ElectricCar my_beetle = Car('volkswagen','beetle','2019') print(my_beetle.get_descriptive_name()) my_tesla = ElectricCar('tesla','model s','2019') print(my_tesla.get_descriptive_name()) my_tesla.battery.describe_battery() my_tesla.battery.get_range() import car my_beetle = car.Car('volkswagen','beetle','2019') print(my_beetle.get_descriptive_name()) my_tesla = car.ElectricCar('tesla','model s','2019') print(my_tesla.get_descriptive_name()) from car import *
##this module was created to import Car2 from the car.py module. from car import ElectricCar my_tesla = ElectricCar("tesla", "model s", 2016) print(my_tesla.get_descriptive_name()) my_tesla.battery.describe_battery() my_tesla.battery.get_range()
#从一个模块中导入多个类 from car import Car, ElectricCar my_beetle = Car("volkswagen", "beetle", 2016) print(my_beetle.get_descriptive_name()) my_tesla = ElectricCar("tesla", "roadster", 2016) print(my_tesla.get_descriptive_name()) print("\n") #导入整个模块 import car my_beetle = car.Car("wolkswagen", "beetle", 2016) print(my_beetle.get_descriptive_name()) my_tesla = car.Car("tesla", "roadster", 2016) print(my_tesla.get_descriptive_name()) print("\n") #导入模块中的所有类 from car import * my_beetle = Car("wolkswagen", "beetle", 2016) print(my_beetle.get_descriptive_name()) my_tesla = ElectricCar("tesla", "roadster", 2016) print(my_tesla.get_descriptive_name())
#!/usr/bin/env python # -*- coding: utf-8 -*- # # my_electric_car.py # # Copyright 2017 c5220056 <c5220056@GMPTIC> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # from car import ElectricCar my_tesla = ElectricCar('tesla', 'model s', 2016) print(my_tesla.get_descriptive_name()) my_tesla.battery.describe_battery() my_tesla.battery.get_range()
from car import ElectricCar my_tesla = ElectricCar('tesla', "model s", 2016) my_tesla.battery.describe_battery()