Picture this: object then method
Construct the student, then ask for the average.
Student(...)object
→
self.scoreslist
→
average()mean
Each step highlights the matching Python line. Program output appears only when a line that prints actually runs.
Ready
1class Student:
2def __init__(self, name, scores):
3 self.name = name
4 self.scores = scores
5def average(self):
6 return sum(self.scores) / len(self.scores)
7print(f"{s.name} {s.average()}")
Output:
1class Student:
2def __init__(self, name, scores):
3 self.name = name
4 self.scores = scores
5def average(self):
6 return sum(self.scores) / len(self.scores)
7name = input()
8scores = list(map(int, input().split()))
9s = Student(name, scores)
10print(f"{s.name} {s.average()}")