Q.For the SMIS system extended in Chapter 6 let us do the following:
7.2 Add another user defined function to the above menu to check if the student has short attendance or not. The function should accept total number of working days in a month and check if the student is a defaulter by calculating his or her attendance using the formula: Count of days the student was present or the total number of working days. In case the attendance calculated is less than 78%, the function should return 1 indicating short attendance otherwise the function should return 0 indicating attendance is not short.
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 →Add one more user-defined function to the SMIS menu: shortAttendance(daysPresent, workingDays) computes attendance % = (days present / total working days) × 100 and returns 1 when it is below 78% (short), else 0.
The idea. Because 7.1 made SMIS modular, adding a feature is now just one new function plus one menu line — that is the payoff of user-defined functions. Note the stem's formula text ("Count of days the student was present or the total number of working days") is a printing slip: the intended formula is the count of days present divided by the total working days, expressed as a percentage.
def shortAttendance(daysPresent, workingDays):
"""Return 1 if attendance is short (< 78%), else 0."""
attendance = (daysPresent / workingDays) * 100
print("Attendance:", round(attendance, 2), "%")
if attendance < 78:
return 1
else:
return 0
Wiring it into the menu of 7.1 (new option 3; Exit moves to 4):
print("3. Check short attendance")
...
elif choice == 3:
working = int(input("Enter total number of working days in the month: "))
present = int(input("Enter number of days the student was present: "))
if shortAttendance(present, working) == 1:
print("ALERT: the student is a DEFAULTER (attendance below 78%).")
else:
print("Attendance is not short.")
Key points
- The function returns a flag (1 or 0) rather than printing the verdict — the caller decides how to present it, which keeps the function reusable (e.g. to count defaulters across a class).
daysPresent / workingDaysuses true division, so the percentage is exact. …
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.