In: Computer Science
Write an IPO diagram and Python program that has two functions, main and determine_grade.
main – Should accept input of five numeric grades from the user USING A LOOP. It should then calculate the average numeric grade. The numeric average should be passed to the determine_grade function.
determine_grade – should display the letter grade to the user based on the numeric average:
Greater than 90: A
80-89: B
70-79: C
60-69: D
Below 60: F
Modularity: Your program should contain 2 functions: a main function to accept input from the user and calculate average and a second function to display the letter grade.
Input Validation: The test scores entered by the user should be in the range 1-100
Output: Display both the numeric average (rounded to two decimals) and the letter grade
Sample Dialog:
Enter score #1 in range 1-100: 900
Error: Re-enter score #1 in range 1-100: 90
Enter score #2 in range 1-100: 65
Enter score #3 in range 1-100: 98
Enter score #4 in range 1-100: 33
Enter score #5 in range 1-100: 75
Your average is: 72.20 which is a(n) C
Python Code:-
def determine_grade(n): #Function
if(n>=90):
print("Your average is %.2f which is an A" %n)
elif(n>=80):
print("Your average is %.2f which is a B" %n)
elif(n>=70):
print("Your average is %.2f which is a C" %n)
elif(n>=60):
print("Your average is %.2f which is a D" %n)
else:
print("Your average is %.2f which is a F" %n)
if __name__ == "__main__": #Main function
total=0
avg=0
for i in range(5):
x=int(input("Enter score #%d in range 1-100: " %(i+1)))
while True:
if(x>=1 and x<=100): #Validation
total=total+x
break
else:
x=int(input("Re-Enter score #%d in range 1-100: " %(i+1)))
avg=total/5
determine_grade(avg) #Passing average grade to the function determine grade
I am attaching the Screenshot of the code snippet with output as well below:-
Input-process-output(IPO) diagram:-