Advertisement
trds

9ianuarie2021

Jan 9th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. class Persoana(object):
  2.      def __init__(self,n,v,g,h,s):
  3.          #constructorul clasei
  4.          self.nume = n
  5.          self.__varsta = v
  6.          self.__greutate = g
  7.          self.__inaltime = h
  8.          self.sex = s
  9.      def __repr__(self):
  10.          return 'Nume ' + self.nume + ' varsta ' + str(self.__varsta) + ' greutate ' + str(self.__greutate) + ' inaltime ' + str(self.__inaltime) + ' sex ' + self.sex
  11.      def getBMI(self):
  12.          h = self.__inaltime / 100
  13.          coef = self.__greutate / (h**2)
  14.          return coef
  15.      def getVarsta(self):
  16.          return self.__varsta
  17.      def getGreutate(self):
  18.          return self.__greutate
  19.      def setGreutate(self,newG):
  20.          self.__greutate = newG
  21.      def getInaltime(self):
  22.          return self.__inaltime
  23.      def getStatus(self):
  24.          indice = self.getBMI()
  25.          if indice < 18.5:
  26.              return 'slab'
  27.          elif indice >= 18.5 and indice < 25:
  28.              return 'normal'
  29.          elif indice >= 25 and indice < 30:
  30.              return 'supraponderal'
  31.          elif indice >= 30:
  32.              return 'obez'
  33.      def __eq__(self, other):
  34.          if other == None:
  35.              return False
  36.          if isinstance(other,Persoana):
  37.              if self.nume == other.nume and self.__varsta == other.__varsta:
  38.                  return True
  39.          return False
  40.      def __lt__(self, other):
  41.          if other == None:
  42.              return False
  43.          if isinstance(other,Persoana):
  44.              if self.__varsta < other.__varsta:
  45.                  return True
  46.          return False
  47.      def __gt__(self, other):
  48.          if other == None:
  49.              return False
  50.          if isinstance(other,Persoana):
  51.              if self.__varsta > other.__varsta:
  52.                  return True
  53.          return False
  54.  
  55. p1 = Persoana('Ionel',23,85,183,'MASCULIN')
  56. print(p1)
  57. print(p1.nume)
  58. #print(p1.greutate)
  59. print(p1.getBMI())
  60. print(p1.getInaltime())
  61. p1.setGreutate(80)
  62. print(p1.getGreutate())
  63. print(p1.getVarsta())
  64. print(p1.getBMI())
  65. print(p1.getStatus())
  66. p2 = Persoana('Bianca',20,54,164,'Feminin')
  67. print(p2.getStatus())
  68. print(p1 == p2)
  69. p3 = Persoana('Ionel',23,87,190,'Masculin')
  70. print(p1 == p3)
  71. print(p1 < p2)
  72. p4 = Persoana('Alex',20,60,170,'Masculin')
  73. p5 = Persoana('Ana',21,60,170,'Feminin')
  74. l = [p1,p2,p3,p4,p5]
  75. cond = False
  76. while cond == False:
  77.     cond = True
  78.     for i in range(len(l)-1):
  79.         if l[i] > l[i+1]:
  80.             l[i], l[i+1] = l[i+1],l[i]
  81.             cond = False
  82. print(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement