uccjshrimpton

First OOP Program Test

May 20th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. class car:  
  2.     def __init__(self,manufacturer,name,year):
  3.         self.nowheels = 4
  4.         self.manufacturer = manufacturer
  5.         self.name = name
  6.         self.year = year
  7.         self.features = []
  8.  
  9.     def description(self):
  10.         print("\n---",self.manufacturer.upper(),self.name.upper(),"---")
  11.         print("The manufacturer of this car is",self.manufacturer)
  12.         print("The name of this model of car is",self.name)
  13.         print("The year this car was made is",self.year)
  14.         print("This car has",self.nowheels,"wheels.")
  15.         if self.features != []:
  16.             print("This car has...",", ".join(self.features))
  17.  
  18.     def newfeatures(self,no_of_features):
  19.         for feature in range(no_of_features):
  20.             self.features.append(input("What feature does this car have?"))
  21.  
  22. FordMondeo = car("Ford","Mondeo",1995)
  23. FiatPunto = car("Fiat","Punto",1997)
  24.  
  25. FordMondeo.newfeatures(3)
  26.  
  27. FordMondeo.description()
  28. FiatPunto.description()
Advertisement
Add Comment
Please, Sign In to add comment