Can someone write a program for this. Preferably in python Write a small program
ID: 3868835 • Letter: C
Question
Can someone write a program for this. Preferably in python Write a small program that will create an array of numbers (specifically of integers, if you can easily do so). The program should then fill the array with odd numbers, starting with l, and moving upwards. The program must print out all the numbers in the array, and it must print out the sum of the numbers in the array, Make sure that the array has at least 5 elements in it. Write a small program that will define a new class, named Car. Each Car has a topSpeed, and has a number of doors (2 doors or 4 doors, typically, although I think there was a 3 door a while back). Give the Car class a Print method, and make sure to properly encapsulate everything in the class. In the Main function in your program, create two Cars, initialize them with different values, print them out, change the top speed on one of the Cars to be a different number, then print them out again.Explanation / Answer
class Vehicle(object): # no instance of this class should be created def __init__(self, typ, make, model, color, year, miles): self.typ = typ self.make = make self.model = model self.color = color.lower() self.year = year self.miles = miles def vehicle_print(self): print('Vehicle Type: ' + str(self.typ)) print('Make: ' + str(self.make)) print('Model: ' + str(self.model)) print('Color: ' + str(self.color)) print('Year: ' + str(self.year)) print('Miles driven: ' + str(self.miles)) class GasVehicle(Vehicle): def __init__(self, fuel_tank, *args): self.fuel_tank = fuel_tank Vehicle.__init__(self, *args) def vehicle_print(self): Vehicle.vehicle_print(self) print('Fuel capacity (gallons): ' + str(self.fuel_tank)) class ElectricVehicle(Vehicle): def __init__(self, energy_storage, *args): self.energy_storage = energy_storage Vehicle.__init__(self, *args) def vehicle_print(self): Vehicle.vehicle_print(self) print('Energy Storage (Kwh): ' + str(self.energy_storage)) class HeavyVehicle(GasVehicle): # no instance of this class should be created def __init__(self, max_weight, wheels, length, *args): self.max_weight = max_weight self.wheels = wheels self.length = length GasVehicle.__init__(self, *args) def vehicle_print(self): GasVehicle.vehicle_print(self) print('Maximum load (tons): ' + str(self.max_weight)) print('Wheels: ' + str(self.wheels)) print('Length (m): ' + str(self.length)) class ConstructionTruck(HeavyVehicle): def __init__(self, cargo, *args): self.cargo = cargo HeavyVehicle.__init__(self, *args) def vehicle_print(self): HeavyVehicle.vehicle_print(self) print('Cargo: ' + str(self.cargo)) class Bus(HeavyVehicle): def __init__(self, seats, * args): self.seats = seats HeavyVehicle.__init__(self, *args) def vehicle_print(self): HeavyVehicle.vehicle_print(self) print('Number of seats: ' + str(self.seats)) class HighPerformance(GasVehicle): # no instance of this class should be created def __init__(self, hp, top_speed, *args): self.hp = hp self.top_speed = top_speed GasVehicle.__init__(self, *args) def vehicle_print(self): GasVehicle.vehicle_print(self) print('Horse power: ' + str(self.hp)) print('Top speed: ' + str(self.top_speed)) class SportCar(HighPerformance): def __init__(self, gear_box, drive_system, *args): self.gearbox = gear_box self.drive_system = drive_system HighPerformance.__init__(self, *args) def vehicle_print(self): HighPerformance.vehicle_print(self) print('Gear box: ' + self.gearbox) print('Drive system: ' + self.drive_system) bmw = GasVehicle(30, 'SUV', 'BMW', 'X5', 'silver', 2003, 120300) # regular car bmw.vehicle_print() print tesla = ElectricVehicle(85, 'Sport', 'Tesla', 'Model S', 'red', 2014, 1243) # electric car tesla.vehicle_print() print lambo = SportCar('manual', 'rear wheel', 650, 160, 23, 'race car', 'Lamborgini', 'Enzo', 'dark silver', 2014, 3500) # sportscar lambo.vehicle_print() print truck = ConstructionTruck('cement', 4, 12, 21, 190, 'transport', 'Dirt Inc.', 'Dirt Blaster 100', 'blue', 1992, 120030) # Construction truck truck.vehicle_print()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.