Let us add more functionality to our SMIS developed in Chapter 5.
6.1 Write a menu driven program that has options to
• accept the marks of the student in five major subjects in Class X and display the same.
• calculate the sum of the marks of all subjects. Divide the total marks by number of subjects (i.e. 5), calculate percentage = total marks/5 and display the percentage.
• Find the grade of the student as per the following criteria:
| Criteria | Grade |
|---|---|
| percentage > 85 | A |
percentage < 85 && percentage >= 75 B percentage < 75 && percentage >= 50 C percentage > 30 && percentage <= 50 D percentage <30 Reappear
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Build a while-True menu that dispatches to functions sharing one marks list — accept/display the five marks, compute percentage = total marks / 5, and grade it through a top-down if–elif ladder implementing the given criteria.
The idea. A menu-driven program is an intentional infinite loop (while True) that shows options, reads a choice, and dispatches with if–elif — exiting via break. Keeping the marks in a list shared by small functions mirrors how the SMIS case study grows chapter by chapter: each menu option becomes one function.
The grade criteria table has two printed quirks we must resolve honestly: percentage exactly 50 appears in both the C row (>= 50) and the D row (<= 50), and percentage exactly 30 appears in neither (D needs > 30, Reappear needs < 30). A top-down ladder settles both: 50 lands in C (its test runs first) and 30 falls through to Reappear.
Program
marks = []
subjects = ["English", "Maths", "Science", "Social Science", "Hindi"]
def accept_and_display():
marks.clear()
for sub in subjects:
marks.append(float(input("Enter marks in " + sub + " (out of 100): ")))
print("Marks entered:")
for i in range(5):
print(" " + subjects[i] + ":", marks[i])
def percentage():
if not marks:
print("Please enter marks first (option 1).")
return None
total = sum(marks)
per = total / 5 # 5 subjects
print("Total marks :", total)
print("Percentage :", per)
return per
def grade():
per = percentage()
if per is None:
return
if per > 85:
g = "A"
elif per >= 75:
g = "B"
elif per >= 50:
g = "C"
elif per > 30:
g = "D"
else:
g = "Reappear"
print("Grade :", g)
while True:
print()
print("SMIS - Student Marks Menu")
print("1. Accept and display marks (5 subjects)")
print("2. Calculate and display percentage")
print("3. Find grade")
print("4. Exit")
ch = input("Enter your choice (1-4): ")
if ch == "1":
accept_and_display()
elif ch == "2":
percentage()
elif ch == "3":
grade()
elif ch == "4":
print("Goodbye!")
break
else:
print("Invalid choice. Enter 1-4.")
Sample run (choices 1 then 3 then 4), marks 90, 85, 78, 88, 92:
Enter your choice (1-4): 1
Enter marks in English (out of 100): 90
Enter marks in Maths (out of 100): 85
Enter marks in Science (out of 100): 78
Enter marks in Social Science (out of 100): 88 …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.