2. Create a function that has 5 parameters. This function will calculate the average grade of 5 subjects.
The 5 grades on each subject should be 1 line of user input.
sample output:
Enter 5 Grades: 70 72 73 74 60
Your average grade is 69.8 and you are failed.
def average_grade(g1, g2, g3, g4, g5):
average = (g1 + g2 + g3 + g4 + g5) / 5
return average
while True:
try:
tests = list(map(int, input('Enter 5 Grades: ').split()))
except:
print('incorrect input')
continue
if len(tests) != 5:
print('enter five grades')
continue
if average_grade(*tests) < 70:
s = 'failed'
else:
s = 'succeeded'
print('Your average grade is {} and you are {}.'.format(average_grade(*tests), s))
break
Comments
Leave a comment