Advertisement
Guest User

vehicle.py

a guest
Sep 30th, 2016
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.52 KB | None | 0 0
  1. #object for the vehicle
  2.  
  3. class vehicles(object):
  4.  
  5.     def __init__(self,name):
  6.         print ("Database initialised") #initialise all variables
  7.         make = ""
  8.         model= ""
  9.         year = 0
  10.         cost = 0
  11.         mileage = 0
  12.         type_of_v = ""
  13.         sold = False
  14.         self.make = ""
  15.         self.model= ""
  16.         self.year = 0
  17.         self.cost = 0
  18.         self.mileage = 0
  19.         self.type_of_v = ""
  20.         self.sold = False
  21.         self.will_it_blend = False
  22.  
  23.     def new_entry(self): #takes all required information and records it
  24.         make = str(input("Make of vehicle? ")).upper()
  25.         self.make = make
  26.         model = str(input("Model of vehicle? ")).upper()
  27.         self.model = model
  28.         year = int(input("What year is the vehicle? "))
  29.         self.year = year
  30.         cost = int(input("What was the cost of the vehicle new? "))
  31.         self.cost = cost
  32.         mileage = int(input("What was the vehicle's mileage? "))
  33.         self.mileage = mileage
  34.         type_of_v = str(input("Car, truck, or motorcycle? ")).upper()
  35.         self.type_of_v = type_of_v
  36.         sell_cost = 0
  37.         year_sold = int(input("What year is the vehicle being sold in? "))
  38.         age = self.year - year_sold
  39.         if age <= 1:
  40.             sell_cost = (self.cost - (self.cost*0.25))
  41.             sell_cost = ("%.2f" % sell_cost)
  42.         elif age <= 3:
  43.             sell_cost = cost / 2.00
  44.             sell_cost = ("%.2f" % sell_cost)
  45.         else:
  46.             sell_cost = cost - (cost*0.63)
  47.             sell_cost = ("%.2f" % sell_cost)
  48.         self.sell_cost = sell_cost
  49.         self.year_sold = year_sold
  50.         self.age = age
  51.  
  52.  
  53.     def price_quote(self): #Calculates just the price of the vehicle and records it
  54.         print ("The vehicle is worth about $"+self.sell_cost+".")
  55.  
  56.     def sell(self): #calculates and records the cost of the vehicle, and the date it was sold on
  57.         sold = True
  58.         self.sold = sold
  59.         month_day_sold=str(input("What day and month was this sold? ")).upper()
  60.         year_sold = int(input("What year was this vehicle sold? "))
  61.         age = self.year - self.year_sold
  62.         if age <= 1:
  63.             sell_cost = (self.cost - (self.cost*0.25))
  64.             sell_cost = ("%.2f" % sell_cost)
  65.         elif age <= 3:
  66.             sell_cost = cost / 2.00
  67.             sell_cost = ("%.2f" % sell_cost)
  68.         else:
  69.             sell_cost = cost / 3.00
  70.             sell_cost = ("%.2f" % sell_cost)
  71.         self.sell_cost = sell_cost
  72.         self.month_day_sold = month_day_sold
  73.         self.year_sold = year_sold
  74.         self.age = age
  75.        
  76.     def print_full(self): #prints all the information on the entry
  77.         self.will_it_blend = True
  78.         try:
  79.             self.make=str(self.make)
  80.         except NameError:
  81.             print ("Nothing is in this entry!")
  82.             self.will_it_blend = False
  83.         if self.will_it_blend == False:
  84.             print ("")
  85.  
  86.         else:
  87.             print ("Make: "+self.make)
  88.             print ("Model: "+self.model)
  89.             print ("Year: "+str(self.year))
  90.             print ("Price new: "+str(self.cost))
  91.             try:
  92.                 print ("Price used: "+str(self.sell_cost))
  93.             except AttributeError:
  94.                 print ("No price has been calculated")
  95.             print ("Mileage: "+str(self.mileage))
  96.             if self.sold == True:
  97.                 print ("Date sold: "+self.month_day_sold+", "+str(self.year_sold))
  98.             print ("Type of vehicle: "+self.type_of_v)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement