-2
Hi, I’m a little confused about the concept of lists and tuples in Python. In my research I noticed that tuple is a "kind of immutable list", but, despite the definition, I still can not differentiate properly at the time of developing my program. I’m stuck on the following question:
- Build a class called Class that will represent a class of students. This class will have as attributes an array of strings containing student names and an array of floats containing each student’s grades. The class must have a constructor that will receive the two arrays as parameters, so that they can be initialized. A class should also have a method called calculator calculate and return average student grades and a print method print on the screen the list of students' names with their respective grades.
For that part, I thought of the following resolution:
class Turma:
nome = []
notas = []
def __init__(self,nome,notas):
self.nome = nome
self.notas = notas
def calcularMediaNota(self):
media = sum(notas)/len(nome)
return media
def imprimirAlunos(self):
relacao = zip(nome,notas)
relacaoSet = set(relacao)
for i in range(0,len(nome)):
print(relacaoSet)
The question continues to request:
- Make a class called Turmademo that must have a main method. Within the main method, a new object of the class Class must be instantiated. The constructor of the class Class should receive an array of strings containing 10 student names and an array of floats containing 10 notes, one for each student. Then to instantiate the object, execute the methods compute and print from the instantiated object.
In this second part I tried to create a resolution using test attributes, however, I believe that the model I developed so far presents errors that prevent me from reaching the final resolution.
class TurmaDemo:
def main(self):
turma_dados = (
('Teste_1',10)
('Teste_2',9)
('Teste_3',8)
('Teste_4',7)
('Teste_5',6)
('Teste_6',5)
('Teste_7',4)
('Teste_8',3)
('Teste_9',2)
('Teste_10',1)
)
turma = [Turma(*i) for i in turma_dados]
print('A média da turma é: {}'.format(Turma.calcularMediaNota(turma)))
Turma.imprimirAlunos()
TypeError: 'tuple' object is not callable
My level in Python and POO language is not yet well developed
If you can help me find a north I can follow or indicate the mistakes I’ve been making, it would be of great help.