m=int(input("Enter your mark "))
if(m>=80):
print("You got A grade")
elif(m>=60):
print("You got B grade")
elif(m>=40):
print("You got C grade")
else:
print("Failed in this Exam ")
marks = 88
grade = 'A' if marks >= 90 else 'B' if marks >= 80 else 'C'
print(f"Marks: {marks}, Grade: {grade}")
Here’s how to calculate the average marks for a class and assign a grade based on the average:
marks = [85, 78, 92, 68, 74, 88, 90]
# Calculate the total and average marks
total_marks = sum(marks)
average_marks = total_marks / len(marks)
# Assign grade based on the average
if average_marks >= 90:
grade = 'A'
elif average_marks >= 80:
grade = 'B'
elif average_marks >= 70:
grade = 'C'
elif average_marks >= 60:
grade = 'D'
else:
grade = 'F'
print(f"Average Marks: {average_marks:.2f}, Grade: {grade}")
Output
Average Marks: 82.14, Grade: B