Files
pplus-web/mojo/stress/grade-book.mojo
T
2026-10-05 03:03:38 +00:00

25 lines
767 B
Mojo

# probe: a list of structs, averages, and round()
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
# expect-stdout: ada 84.0 84.0
# expect-stdout: bo 77.0 77.0
@fieldwise_init
struct Student(Copyable, Movable):
var name: String
var scores: List[Int]
def mean(self) -> Float64:
var total = 0
for s in self.scores:
total += s
return Float64(total) / Float64(len(self.scores))
def main():
var a: List[Int] = [90, 85, 77]
var b: List[Int] = [60, 72, 81, 95]
var people = List[Student]()
people.append(Student("ada", a^))
people.append(Student("bo", b^))
for p in people:
print(p.name, p.mean(), round(p.mean()))