Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Aluno_v5.py
- class UC:
- def __init__(self, pNome, pAcronimo):
- self.mNome = pNome
- self.mAcronimo = pAcronimo
- # def __init__
- # utilizado para representações em outputs diretos
- def __str__(self):
- strUC = ""
- strUC = f"{self.mNome} ({self.mAcronimo})"
- return strUC
- # def __str__
- # repr controla a representação em situações indiretas
- # como no interior de coleção
- def __repr__(self):
- # return self.__str__()
- return self.mAcronimo
- # def __repr__
- # class UC
- fp = UC ("Fundamentos de Programação", "FP")
- ia = UC ("Inteligência Artificial", "IA")
- cn = UC ("Computação na Nuvem", "CN")
- u3 = UC ("U three", "U3")
- UCS_POSSIVEIS = [fp, ia, u3]
- class Aluno:
- # self representa o objeto q está a ser
- # trabalhado
- def __init__(
- self,
- # tantos params quantas as props/atributos/membros de dados
- pNome:str="Anonymous",
- pNum:int=0,
- pListaUCs:list=[]
- ):
- self.mNome = pNome
- self.mNum = pNum
- self.mListaUCs = pListaUCs
- # podem existir propriedades
- # NÃO configuráveis pelos params
- # coleção paralela à coleção das UCs
- self.mListaClassificacoes = []
- # inicializar as classificações das UCs, sempre a "nenhuma"
- for uc in self.mListaUCs:
- self.mListaClassificacoes.append(None)
- # def __init__
- def registarClassificacao(
- self, # qual Aluno?
- pUC:UC, # qual UC?
- pClassificacao:int # qual classificação?
- ):
- bCautela = pUC in self.mListaUCs
- if (bCautela):
- for idx in range(len(self.mListaUCs)):
- uc = self.mListaUCs[idx]
- bUCParaQualRegistarNota = \
- uc.mAcronimo == pUC.mAcronimo
- if (bUCParaQualRegistarNota):
- self.mListaClassificacoes[idx]=pClassificacao
- return True
- # if
- # for
- return False
- # def registarClassificacao
- def __str__(self):
- strAluno = ""
- strAluno+=f"Nome: {self.mNome}\n"
- strAluno += f"Número: {self.mNum}\n"
- qUCs = len(self.mListaUCs)
- strAluno += "Unidades e classificações conhecidas:\n"
- strUCs = ""
- for idx in range(qUCs):
- uc = self.mListaUCs[idx]
- classf = self.mListaClassificacoes[idx]
- strUCs+=f"{uc.mAcronimo} : {classf}\n"
- # for
- #strAluno += f"inscrito em {qUCs} UCs: {self.mListaUCs}\n"
- if(strUCs==""):
- strAluno+="Não tem inscrições.\n"
- else:
- strAluno += strUCs
- return strAluno
- # def __str__
- def __repr__(self):
- return self.__str__()
- # def __repr__
- def inscreverEmUC(
- self,
- pUC:UC,
- pUCsPossiveis=UCS_POSSIVEIS
- ):
- bUCPossivel = pUC in pUCsPossiveis
- bJaInscrito = pUC in self.mListaUCs
- bPossivelInscrever = bUCPossivel and (not bJaInscrito)
- if(bPossivelInscrever):
- self.mListaUCs.append(pUC)
- self.mListaClassificacoes.append(None)
- return True#, bUCPossivel, bJaInscrito
- else:
- return False#, bUCPossivel, bJaInscrito
- # if-else
- # def inscreverEmUC
- # class Aluno
- artur = Aluno("Artur", 293829, ) #OK
- rita = Aluno("Rita", 654332, [fp, ia]) #OK
- rita.inscreverEmUC(u3)
- print(artur)
- print(rita)
- rita.registarClassificacao(ia, 20)
- print(rita)
Advertisement
Add Comment
Please, Sign In to add comment