It's code from my programming lesson in school, could you review it? We've tried to calculate cylinder parameters in a simple way.
from math import pi
from math import radians
from math import sin
from math import atan
class Cilindrs:
def __init__(self, a, b):
self._augstums = a
self._Radius = b
def set_H(self,val):
self._augstums=val
def set_R(self,val):
self._Radius=val
def get_D(self):
return round(self._Radius*2, 2)
def get_rl(self):
return round(self._Radius*2*pi, 2)
def get_Spam(self):
return round (pi*self._Radius**2, 2)
def get_Ssanu(self):
return round(self.get_rl()*self._augstums, 2)
def get_Spiln(self):
return round(self.get_Ssanu()+self.get_Spam(), 2)
def get_V(self):
return round(pi*self._Radius**2*self._augstums, 2)
cil = Cilindrs(8, 2)
print (cil.get_D())
print (cil.get_rl())
print (cil.get_Spam())
print (cil.get_Ssanu())
print (cil.get_Spiln())
print (cil.get_V())
class InclinedCylinder (Cilindrs):
def init(self, radiuss, augstums):
self._rad = radiuss
self._augst = augstums
self.alpha = atan(self._augst / self._rad)
def getL(self):
return round(self._augst * sin(self.alpha), 2)
mtr = InclinedCylinder (4,10)
print ('\n')
print (mtr.getL())
print (mtr.getD())
print (mtr.getC())
print (mtr.getSpam())
print (mtr.getSsanu())
print (mtr.getS())
print (mtr.getV())
Maybe you can help me how to optimize code to make it work faster and cleaner? There is also one more InclinedCylinder, which differs a bit, because has alpha angle.
source https://stackoverflow.com/questions/75313317/cylinder-parameters-count-are-done-right
Comments
Post a Comment