am_dot_com

FP 2022-11-29

Nov 29th, 2022 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. # Aluno_v5.py
  2.  
  3. class UC:
  4. def __init__(self, pNome, pAcronimo):
  5. self.mNome = pNome
  6. self.mAcronimo = pAcronimo
  7.  
  8. # def __init__
  9.  
  10. # utilizado para representações em outputs diretos
  11. def __str__(self):
  12. strUC = ""
  13. strUC = f"{self.mNome} ({self.mAcronimo})"
  14. return strUC
  15.  
  16. # def __str__
  17.  
  18. # repr controla a representação em situações indiretas
  19. # como no interior de coleção
  20. def __repr__(self):
  21. # return self.__str__()
  22. return self.mAcronimo
  23. # def __repr__
  24. # class UC
  25.  
  26. fp = UC ("Fundamentos de Programação", "FP")
  27. ia = UC ("Inteligência Artificial", "IA")
  28. cn = UC ("Computação na Nuvem", "CN")
  29. u3 = UC ("U three", "U3")
  30. UCS_POSSIVEIS = [fp, ia, u3]
  31.  
  32. class Aluno:
  33. # self representa o objeto q está a ser
  34. # trabalhado
  35. def __init__(
  36. self,
  37. # tantos params quantas as props/atributos/membros de dados
  38. pNome:str="Anonymous",
  39. pNum:int=0,
  40. pListaUCs:list=[]
  41. ):
  42. self.mNome = pNome
  43. self.mNum = pNum
  44. self.mListaUCs = pListaUCs
  45.  
  46. # podem existir propriedades
  47. # NÃO configuráveis pelos params
  48. # coleção paralela à coleção das UCs
  49. self.mListaClassificacoes = []
  50. # inicializar as classificações das UCs, sempre a "nenhuma"
  51. for uc in self.mListaUCs:
  52. self.mListaClassificacoes.append(None)
  53.  
  54. # def __init__
  55.  
  56. def registarClassificacao(
  57. self, # qual Aluno?
  58. pUC:UC, # qual UC?
  59. pClassificacao:int # qual classificação?
  60. ):
  61. bCautela = pUC in self.mListaUCs
  62. if (bCautela):
  63. for idx in range(len(self.mListaUCs)):
  64. uc = self.mListaUCs[idx]
  65. bUCParaQualRegistarNota = \
  66. uc.mAcronimo == pUC.mAcronimo
  67. if (bUCParaQualRegistarNota):
  68. self.mListaClassificacoes[idx]=pClassificacao
  69. return True
  70. # if
  71. # for
  72. return False
  73. # def registarClassificacao
  74.  
  75. def __str__(self):
  76. strAluno = ""
  77. strAluno+=f"Nome: {self.mNome}\n"
  78. strAluno += f"Número: {self.mNum}\n"
  79.  
  80. qUCs = len(self.mListaUCs)
  81. strAluno += "Unidades e classificações conhecidas:\n"
  82. strUCs = ""
  83. for idx in range(qUCs):
  84. uc = self.mListaUCs[idx]
  85. classf = self.mListaClassificacoes[idx]
  86. strUCs+=f"{uc.mAcronimo} : {classf}\n"
  87. # for
  88. #strAluno += f"inscrito em {qUCs} UCs: {self.mListaUCs}\n"
  89. if(strUCs==""):
  90. strAluno+="Não tem inscrições.\n"
  91. else:
  92. strAluno += strUCs
  93.  
  94. return strAluno
  95. # def __str__
  96.  
  97. def __repr__(self):
  98. return self.__str__()
  99. # def __repr__
  100.  
  101. def inscreverEmUC(
  102. self,
  103. pUC:UC,
  104. pUCsPossiveis=UCS_POSSIVEIS
  105. ):
  106. bUCPossivel = pUC in pUCsPossiveis
  107. bJaInscrito = pUC in self.mListaUCs
  108. bPossivelInscrever = bUCPossivel and (not bJaInscrito)
  109. if(bPossivelInscrever):
  110. self.mListaUCs.append(pUC)
  111. self.mListaClassificacoes.append(None)
  112. return True#, bUCPossivel, bJaInscrito
  113. else:
  114. return False#, bUCPossivel, bJaInscrito
  115. # if-else
  116. # def inscreverEmUC
  117. # class Aluno
  118.  
  119. artur = Aluno("Artur", 293829, ) #OK
  120. rita = Aluno("Rita", 654332, [fp, ia]) #OK
  121. rita.inscreverEmUC(u3)
  122. print(artur)
  123. print(rita)
  124.  
  125. rita.registarClassificacao(ia, 20)
  126. print(rita)
Advertisement
Add Comment
Please, Sign In to add comment