# Python Program to Take in the Marks of 5 Subjects and Display the Grade

Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills.

Given the marks of 5 subjects of the student, the task is to display the grade of the student based on the marks in

Python.

Examples:

Example1:

Input:

Enter first subject marks as integer = 75
Enter second subject marks as integer = 79
Enter third subject marks as integer = 65
Enter fourth subject marks as integer = 82
Enter fifth subject marks as integer = 63

Output:

Average of 5 marks = 72.8 Grade =C

Example2:

Input:

Enter first subject marks as integer = 63
Enter second subject marks as integer = 19
Enter third subject marks as integer = 99
Enter fourth subject marks as integer = 85
Enter fifth subject marks as integer = 73

Output:

Average of 5 marks = 67.8 Grade =D

## Program to Take in the Marks of 5 Subjects and Display the Grade in Python

There are several ways to calculate the grade of the student based on the marks of 5 subjects in Python some of them are:

### Method #1:Using IF..elif..else Statements(Static Input)

Approach:

• Give the 5 subject marks as static input and store them in 5 variables.
• Calculate the sum of the 5 subject marks and store it in a variable.
• Divide the sum by 5 to get the average of all the given marks.
• To determine the grade based on the average of the marks, use an if…Elif..else conditions.
• The Exit of the Program.

Below is the implementation:

# Give the 5 subject marks as static input and store them in 5 variables.
marks1 = 95
marks2 = 85
marks3 = 89
marks4 = 93
marks5 = 87
# Calculate the sum of the 5 subject marks and store it in a variable.
summarks = marks1+marks2+marks3+marks4+marks5
# Divide the sum of marks by 5 to get the average of all the given marks.
avgmark = summarks/5
# To determine the grade based on the average of the marks, use an if...Elif..else conditions.
if(avgmark >= 90):
print("Average of 5 marks =", avgmark, 'Grade =A')
elif(avgmark >= 80 and avgmark < 90):
print("Average of 5 marks =", avgmark, 'Grade =B')
elif(avgmark >= 70 and avgmark < 80):
print("Average of 5 marks =", avgmark, 'Grade =C')
elif(avgmark >= 60 and avgmark < 70):
print("Average of 5 marks =", avgmark, 'Grade =D')
else:
print("Average of 5 marks =", avgmark, 'Grade =E')


Output:

Average of 5 marks = 89.8 Grade =B

Explanation:

• The user must enter 5 different values as static input and store them in different variables.
• Then add together all five marks and divide by five to get the average.
• If the average is more than 90, the grade is displayed as “A.”
• If the average is between 80 and 90, the letter “B” is printed.
• If the average is between 70 and 80, the letter “C” is printed.
• If the average is between 60 and 70, the letter “D” is printed.
• If the average falls below 60, the letter “F” is printed.

### Method #2:Using IF..elif..else Statements (User Input separated by newline)

Approach:

• Give the 5 subject marks as user input using int(input()) which converts the string to an integer.
• Store them in 5 separate variables.
• Calculate the sum of the 5 subject marks and store it in a variable.
• Divide the sum by 5 to get the average of all the given marks.
• To determine the grade based on the average of the marks, use an if…Elif..else conditions.
• The Exit of the Program.

Below is the implementation:

# Give the 5 subject marks as user input using int(input()) which converts the string to an integer.
# Store them in 5 separate variables.
marks1 = int(input('Enter first subject marks as integer = '))
marks2 = int(input('Enter second subject marks as integer = '))
marks3 = int(input('Enter third subject marks as integer = '))
marks4 = int(input('Enter fourth subject marks as integer = '))
marks5 = int(input('Enter fifth subject marks as integer = '))
# Calculate the sum of the 5 subject marks and store it in a variable.
summarks = marks1+marks2+marks3+marks4+marks5
# Divide the sum of marks by 5 to get the average of all the given marks.
avgmark = summarks/5
# To determine the grade based on the average of the marks, use an if...Elif..else conditions.
if(avgmark >= 90):
print("Average of 5 marks =", avgmark, 'Grade =A')
elif(avgmark >= 80 and avgmark < 90):
print("Average of 5 marks =", avgmark, 'Grade =B')
elif(avgmark >= 70 and avgmark < 80):
print("Average of 5 marks =", avgmark, 'Grade =C')
elif(avgmark >= 60 and avgmark < 70):
print("Average of 5 marks =", avgmark, 'Grade =D')
else:
print("Average of 5 marks =", avgmark, 'Grade =E')


Output:

Enter first subject marks as integer = 75
Enter second subject marks as integer = 79
Enter third subject marks as integer = 65
Enter fourth subject marks as integer = 82
Enter fifth subject marks as integer = 63
Average of 5 marks = 72.8 Grade =C

### Method #3:Using IF..elif..else Statements and map(),split() functions (User Input separated by spaces)

Approach:

• Give the 5 subject marks as user input separated by spaces using map(), split() functions.
• Store them in 5 separate variables.
• Calculate the sum of the 5 subject marks and store it in a variable.
• Divide the sum by 5 to get the average of all the given marks.
• To determine the grade based on the average of the marks, use an if…Elif..else conditions.
• The Exit of the Program.

Below is the implementation:

# Give the 5 subject marks as user input separated by spaces using map(), split() functions.
# Store them in 5 separate variables.
marks1, marks2, marks3, marks4, marks5 = map(int, input(
'Enter 5 subject marks separated by spaces = ').split())
# Calculate the sum of the 5 subject marks and store it in a variable.
summarks = marks1+marks2+marks3+marks4+marks5
# Divide the sum of marks by 5 to get the average of all the given marks.
avgmark = summarks/5
# To determine the grade based on the average of the marks, use an if...Elif..else conditions.
if(avgmark >= 90):
print("Average of 5 marks =", avgmark, 'Grade =A')
elif(avgmark >= 80 and avgmark < 90):
print("Average of 5 marks =", avgmark, 'Grade =B')
elif(avgmark >= 70 and avgmark < 80):
print("Average of 5 marks =", avgmark, 'Grade =C')
elif(avgmark >= 60 and avgmark < 70):
print("Average of 5 marks =", avgmark, 'Grade =D')
else:
print("Average of 5 marks =", avgmark, 'Grade =E')


Output:

Enter 5 subject marks separated by spaces = 45 96 78 99 92
Average of 5 marks = 82.0 Grade =B

Related Programs: