Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 1.41 KB

File metadata and controls

44 lines (34 loc) · 1.41 KB

6.3 Calculate grades

The problem

Calculate grade of five subjects.

Hint

So, you have to take five inputs. These will be the marks of five subjects. Then, create the average.

Once you have the average. It just running an if-else. And decide the grade.

The Solution

print('Enter your marks:') sub1=int(input("First subject: ")) sub2=int(input("Second subject: ")) sub3=int(input("Third subject: ")) sub4=int(input("Fourth subject: ")) sub5=int(input("Fifth subject: ")) avg=(sub1+sub2+sub3+sub4+sub5)/5ifavg>=90: print("Grade: A") elifavg>=80: print("Grade: B") elifavg>=70: print("Grade: C") elifavg>=60: print("Grade: D") else: print("Grade: F")

Try it on Programming Hero

Explanation

Calculation of average is easy. Add them all and then divide by the count. As we are taking numbers for 5 subjects we are dividing the total by 5.

After that, we are running a simple if-else to determine the grade.

  Next Page  

tags: programming-heropythonpython3problem-solvingprogrammingcoding-challengeinterviewlearn-pythonpython-tutorialprogramming-exercisesprogramming-challengesprogramming-fundamentalsprogramming-contestpython-coding-challengespython-problem-solving

close