Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Persoana(object):
- def __init__(self,n,v,g,h,s):
- #constructorul clasei
- self.nume = n
- self.__varsta = v
- self.__greutate = g
- self.__inaltime = h
- self.sex = s
- def __repr__(self):
- return 'Nume ' + self.nume + ' varsta ' + str(self.__varsta) + ' greutate ' + str(self.__greutate) + ' inaltime ' + str(self.__inaltime) + ' sex ' + self.sex
- def getBMI(self):
- h = self.__inaltime / 100
- coef = self.__greutate / (h**2)
- return coef
- def getVarsta(self):
- return self.__varsta
- def getGreutate(self):
- return self.__greutate
- def setGreutate(self,newG):
- self.__greutate = newG
- def getInaltime(self):
- return self.__inaltime
- def getStatus(self):
- indice = self.getBMI()
- if indice < 18.5:
- return 'slab'
- elif indice >= 18.5 and indice < 25:
- return 'normal'
- elif indice >= 25 and indice < 30:
- return 'supraponderal'
- elif indice >= 30:
- return 'obez'
- def __eq__(self, other):
- if other == None:
- return False
- if isinstance(other,Persoana):
- if self.nume == other.nume and self.__varsta == other.__varsta:
- return True
- return False
- def __lt__(self, other):
- if other == None:
- return False
- if isinstance(other,Persoana):
- if self.__varsta < other.__varsta:
- return True
- return False
- def __gt__(self, other):
- if other == None:
- return False
- if isinstance(other,Persoana):
- if self.__varsta > other.__varsta:
- return True
- return False
- p1 = Persoana('Ionel',23,85,183,'MASCULIN')
- print(p1)
- print(p1.nume)
- #print(p1.greutate)
- print(p1.getBMI())
- print(p1.getInaltime())
- p1.setGreutate(80)
- print(p1.getGreutate())
- print(p1.getVarsta())
- print(p1.getBMI())
- print(p1.getStatus())
- p2 = Persoana('Bianca',20,54,164,'Feminin')
- print(p2.getStatus())
- print(p1 == p2)
- p3 = Persoana('Ionel',23,87,190,'Masculin')
- print(p1 == p3)
- print(p1 < p2)
- p4 = Persoana('Alex',20,60,170,'Masculin')
- p5 = Persoana('Ana',21,60,170,'Feminin')
- l = [p1,p2,p3,p4,p5]
- cond = False
- while cond == False:
- cond = True
- for i in range(len(l)-1):
- if l[i] > l[i+1]:
- l[i], l[i+1] = l[i+1],l[i]
- cond = False
- print(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement