Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auta.py:
- class auto:
- i=0
- def __init__(self, obroty=0, bieg=0):
- auto.i +=1
- self.id='id_'+str(auto.i)
- self.obroty = obroty
- self.bieg = bieg
- def predkosc(self):
- print("Obroty: ", self.obroty)
- print("Bieg: ", self.bieg)
- print("Predkosc: ", self.obroty*self.bieg/100)
- def __str__(self):
- return self.a
- class auto_matic(auto):
- def __init__(self, obroty=0, bieg=0):
- super().__init__(obroty, bieg)
- def predkosc(self, wartosc=None):
- if wartosc is not None:
- opt = wartosc*100/2000
- print("Optymalny bieg dla 2000 obrotów i zadanej predkosci: ", round(opt))
- else:
- super().predkosc()
- auto1 = auto(1500, 3)
- auto1.predkosc()
- auto2 = auto_matic(1500, 3)
- auto2.predkosc(70)
- auta_db.py:
- from auta import auto, auto_matic
- import shelve
- db=shelve.open("auta")
- l=sorted(db.keys())
- if (len(l)>0):
- tmp=l[-1].split('_')
- if (len(tmp)==2):
- auta.i=int(tmp[1])
- auto1=auto_matic(2000, 4)
- auto2=auto_matic(2200, 4)
- auto3=auto_matic(1500, 3)
- auto4=auto_matic(1000, 2)
- for ob in (auto1, auto2, auto3, auto4):
- db[ob.id]=ob
- suma=0
- ile=0
- for idd in sorted(db.keys()):
- suma = suma + db[idd].obroty
- ile = ile + 1
- print ('Srednie obroty aut w bazie: '+str(suma/ile))
- db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement