Write a Python program to show students grade by entering five subjects marks then calculate percentage marks , grade is to be calculated as A! If percentage is greater than 90 ,A2 if percentage is greater than 80, B1 if percentage is
Greater then 70,B2 if percentage is greater than 60, other than above grades should be shown
as( Hint use if elif ladder to show grade )
answer this question
Answers
The correct code is written below.
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=float(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A1")
elif(avg>=80 and avg<90):
print("Grade: A2")
elif(avg>=70 and avg<80):
print("Grade: B1")
elif(avg>=60 and avg<70):
print("Grade: B2")
else:
print("Grade: F")
Answer:
The below Python code calculates the percentage and shows the grade of the students:
marks = list(map(int,input().split(" ")))
per= (sum(marks)//len(marks))*100
if(per>=90):
print("Grade: A1")
elif(per>=80 and per<90):
print("Grade: A2")
elif(per>=70 and per<80):
print("Grade: B1")
elif(per>=60 and per<70):
print("Grade: B2")
else:
print("Grade: F")
Explanation:
Let's understand the code above:
- Our task is to take the input marks from the user and then calculate the percentage and print the grade of the student.
- The most convenient way of taking the input marks of the user is to create a marks list and input all the marks obtained by the user.
- This approach will save a lot of your time because you can use the sum function on the list to get the sum of all the marks rather than writing an arithmetic expression for it.
- Then we calculate the percentage and create an if-elif ladder.
- This ladder will check which grade should be awarded for what percentage.
- Lastly, we print the grade and end the program.
#SPJ2