-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaverage.py
More file actions
36 lines (26 loc) · 711 Bytes
/
Copy pathaverage.py
File metadata and controls
36 lines (26 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import statistics
def main():
subjects = 0
grades = []
while True:
try:
input_subjects = int(input("How many subjects? "))
break
except ValueError:
continue
for _ in range(input_subjects):
while True:
print(subjects + 1, ": ", sep="", end="")
try:
input_grade = int(input())
subjects += 1
grades.append(input_grade)
break
except ValueError:
continue
average = get_average(grades)
print(f"Average: {average:.2f}")
def get_average(n):
return statistics.mean(n)
if __name__ == "__main__":
main()