-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrade_calculator.py
More file actions
67 lines (56 loc) · 1.89 KB
/
grade_calculator.py
File metadata and controls
67 lines (56 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# ================================
# Student Grade Calculator
# ================================
def calculate_grade(marks):
"""
Determines grade and message based on marks
"""
if 90 <= marks <= 100:
return "A", "Excellent performance! Keep aiming high 🌟"
elif 80 <= marks < 90:
return "B", "Very Good! You're doing great 👍"
elif 70 <= marks < 80:
return "C", "Good job! A little more effort will help 😊"
elif 60 <= marks < 70:
return "D", "You passed. Focus more next time 💪"
else:
return "F", "Don't give up! Practice makes perfect 🌱"
def get_valid_marks():
"""
Takes marks input and validates it (0-100 only)
"""
while True:
try:
marks = int(input("Enter marks (0-100): "))
if 0 <= marks <= 100:
return marks
else:
print("❌ Marks must be between 0 and 100.")
except ValueError:
print("❌ Invalid input! Please enter numbers only.")
def display_result(name, marks):
"""
Displays the final result
"""
grade, message = calculate_grade(marks)
percentage = marks # Out of 100
print("\n📊 RESULT SUMMARY")
print("-" * 30)
print("Student Name :", name.upper())
print("Marks :", marks, "/100")
print("Percentage :", percentage, "%")
print("Grade :", grade)
print("Message :", message)
print("-" * 30)
def main():
print("🎓 STUDENT GRADE CALCULATOR 🎓")
while True:
name = input("\nEnter student name: ").strip()
marks = get_valid_marks()
display_result(name, marks)
choice = input("\nDo you want to calculate for another student? (y/n): ").lower()
if choice != 'y':
print("\nThank you for using Student Grade Calculator 🙏")
break
# Program execution starts here
main()