Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. auta.py:
  2.  
  3. class auto:
  4.     i=0
  5.     def __init__(self, obroty=0, bieg=0):
  6.         auto.i +=1
  7.         self.id='id_'+str(auto.i)
  8.         self.obroty = obroty
  9.         self.bieg = bieg
  10.     def predkosc(self):
  11.         print("Obroty: ", self.obroty)
  12.         print("Bieg: ", self.bieg)
  13.         print("Predkosc: ", self.obroty*self.bieg/100)
  14.         def __str__(self):
  15.             return self.a
  16.  
  17. class auto_matic(auto):
  18.     def __init__(self, obroty=0, bieg=0):
  19.         super().__init__(obroty, bieg)
  20.     def predkosc(self, wartosc=None):
  21.         if wartosc is not None:
  22.             opt = wartosc*100/2000
  23.             print("Optymalny bieg dla 2000 obrotów i zadanej predkosci: ", round(opt))
  24.         else:
  25.             super().predkosc()
  26.  
  27. auto1 = auto(1500, 3)
  28. auto1.predkosc()
  29.  
  30. auto2 = auto_matic(1500, 3)
  31. auto2.predkosc(70)
  32.        
  33. auta_db.py:
  34.  
  35. from auta import auto, auto_matic
  36. import shelve
  37.  
  38. db=shelve.open("auta")
  39.  
  40. l=sorted(db.keys())
  41. if (len(l)>0):
  42.     tmp=l[-1].split('_')
  43.     if (len(tmp)==2):
  44.         auta.i=int(tmp[1])
  45.  
  46. auto1=auto_matic(2000, 4)
  47. auto2=auto_matic(2200, 4)
  48. auto3=auto_matic(1500, 3)
  49. auto4=auto_matic(1000, 2)
  50.  
  51. for ob in (auto1, auto2, auto3, auto4):
  52.     db[ob.id]=ob
  53.  
  54. suma=0
  55. ile=0
  56. for idd in sorted(db.keys()):
  57.     suma = suma + db[idd].obroty
  58.     ile = ile + 1
  59. print ('Srednie obroty aut w bazie: '+str(suma/ile))
  60. db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement