codescracker


python

Python Program to Calculate Average and Percentage Marks



« Previous Program Next Program »


Calculate Average and Percentage Marks in Python

To calculate average and percentage marks in python, you have to ask from user to enter marks obtained in 5 subjects to calculate and print the average and the percentage marks as shown in the program given below.

Python Programming Code to Calculate Average and Percentage Marks

Following python program ask from user to enter marks obtained in 5 subjects to find the average and percentage marks:

# Python Program - Calculate Average and Percentage Marks

print("Enter 'x' for exit.");
print("Enter marks obtained in 5 subjects: ");
m1 = input();
if m1 == 'x':
    exit();
else:
    m2 = input();
    m3 = input();
    m4 = input();
    m5 = input();
    mark1 = int(m1);
    mark2 = int(m2);
    mark3 = int(m3);
    mark4 = int(m4);
    mark5 = int(m5);
    sum = mark1 + mark2 + mark3 + mark4 + mark5;
    average = sum/5;
    percentage = (sum/500)*100;
    print("Average Marks = ", average);
    print("Percentage Marks = ", percentage,"%");

Here is the sample run of the above Python program shows how to calculate and print average marks and percentage marks of students:

calculate average python

Above screenshot shows the initial output, now you have to enter your marks obtained in 5 subjects one by one and then press enter key to see the average and percentage marks of all the given marks of 5 subjects as shown in below sample screenshot (output):

calculate percentage python

Here is the same program with run directly on python shell:

python calculate average and percentage marks

Program Video with Compile and Run

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test