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 में percentage की गणना का सुत्र है:
(प्राप्त अंक / कुल अंक) × 100
. यह छात्रों को जानने में मदद करता है कि उन्होंने कितनी जानकारी की है।
Example 1: Fixed Marks
total = 500
obtained = 420
percentage = (obtained / total) * 100
print("Percentage =", percentage)
Output:
Percentage = 84.0
Calculates percentage from fixed marks.
Fix की गई जानकारी से percentage निकालता है।
Example 2: User Input Marks
total = float(input("Enter total marks: ") )
obtained = float(input("Enter obtained marks: ") )
percentage = (obtained / total) * 100
print("Percentage =", percentage)
Output:
Enter total marks: 600 Enter obtained marks: 550 Percentage = 91.66666666666666
Takes user input for marks and calculates percentage.
User input se percentage की गणना करता है।
Example 3: Round Off Result
total = 400
obtained = 333
percentage = (obtained / total) * 100
print("Rounded Percentage =", round(percentage, 2))
Output:
Rounded Percentage = 83.25
Rounds off the percentage to 2 decimal places.
Percentage को 2 decimal प्रासियों तक राउंड करता है।