Student Average
Programming Interview
Easy
9 views
Problem Description
You get {x}. Create Student class with method avg(). Output average with 2 decimals.
Input Format
First line n. Second line n integers marks.
Output Format
One number avg.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
n=int(p[0])
marks=list(map(int,p[1:1+n]))
class Student:
def __init__(self,marks):
self.marks=marks
def avg(self):
return (sum(self.marks)/len(self.marks)) if self.marks else 0.0
s=Student(marks)
sys.stdout.write(f'{s.avg():.2f}')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!