Write a Python Program to Read The Marks of Three Subjects And Find The Average of Them

Given the three subjects marks of a student  as an input to the Python program. The Python program should accept the marks of three subjects and find out the average and print it.

It just takes five line code

Accept the marks, find the average and print the average.



Write a Python Program to Read The Marks of Three Subjects And Find The Average of Them


Write a Python Program to Read The Marks of Three Subjects And Find The Average of Them

Let's take 3 floating point variables  to store the marks of three subjects. Use the input function call to ask a user to enter the subject 1,  subject 2 and subject 3 marks.  convert it to a  floating point variable using float() function type conversion.

mark1 = float(input("Enter a Subject 1 Marks : "))
mark2 = float(input("Enter a Subject 2 Marks : "))
mark3 = float(input("Enter a Subject 3 Marks : "))



Once we get all the three subject marks, take another variable average at all the three subjects and divide  the sum by 3. The average  variable will store the floating point number.

average = (mark1 + mark2 + mark3) / 3




Once we find the average, use the print function to print the average by providing a user-friendly message.  average marks of three subjects is and use the floating point format  and print the average  variable.

print("Average Marks of Three Student is : %.2f" %average)




Final Program
=======================

mark1 = float(input("Enter a Subject 1 Marks : "))
mark2 = float(input("Enter a Subject 2 Marks : "))
mark3 = float(input("Enter a Subject 3 Marks : "))

average = (mark1 + mark2 + mark3) / 3

print("Average Marks of Three Student is : %.2f" %average)





OUTPUT
=============

Enter a Subject 1 Marks : 55.9
Enter a Subject 2 Marks : 33.4
Enter a Subject 3 Marks : 90.12
Average Marks of Three Student is : 59.81




OUTPUT
==================

Enter a Subject 1 Marks : 73
Enter a Subject 2 Marks : 84
Enter a Subject 3 Marks : 78
Average Marks of Three Student is : 78.33




Conclusion
=======================

Try running the program by yourself by providing the random  marks as an input to the  program. Comment down below For any queries or suggestions.



Is it possible for you to write the program using integers ??



Post a Comment

0 Comments