Calculate Marks Percentage in Python
In Python, you can calculate the percentage of marks by using the formula: (obtained_marks / total_marks) * 100. This helps students know how much they scored.
Python में, आप अंकों का प्रतिशत निकालने के लिए फार्मूला उपयोग कर सकते हैं: (obtained_marks / total_marks) * 100. इससे छात्रों को पता चलता है कि उन्होंने कितना स्कोर किया।
Example 1: Fixed Marks
total = 500
obtained = 420
percentage = (obtained / total) * 100
print("Percentage =", percentage)
Calculates percentage from fixed marks.
स्थिर अंकों से प्रतिशत की गणना करता है।
Output:
Percentage = 84.0
Example 2: User Input Marks
total = float(input("Enter total marks: "))
obtained = float(input("Enter obtained marks: "))
percentage = (obtained / total) * 100
print("Percentage =", percentage)
Takes user input for marks and calculates percentage.
यूजर से अंक लेकर प्रतिशत की गणना करता है।
Sample Output:
Enter total marks: 600
Enter obtained marks: 550
Percentage = 91.66666666666666
Example 3: Round Off Result
total = 400
obtained = 333
percentage = (obtained / total) * 100
print("Rounded Percentage =", round(percentage, 2))
Rounds off the percentage to 2 decimal places.
प्रतिशत को 2 दशमलव स्थान तक राउंड ऑफ करता है।
Output:
Rounded Percentage = 83.25