Question 5 of 17advanced🔧 ApplyCase Study5 marks

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.

Correct Answer

python

Function to check short attendance

def checkAttendance(workingDays, daysPresent): # Calculate attendance percentage attendance = (daysPresent / workingDays) * 100

# Check if attendance is less than 78%
if attendance < 78:
    return 1  # Short attendance - defaulter
else:
    return 0  # Attendance is not short

Main program

Accepting input from user

totalWorkingDays = int(input("Enter total number of working days: ")) daysPresent = int(input("Enter count of days student was present: "))

Function call

result = checkAttendance(totalWorkingDays, daysPresent)

Display result

if result == 1: print("Student has SHORT ATTENDANCE - Defaulter") else: print("Attendance is satisfactory")

The program defines a user defined function checkAttendance() that accepts two parameters: total number of working days and count of days present.

Inside the function, attendance percentage is calculated using the formula: (daysPresent / workingDays) * 100. The function then checks if the calculated attendance is less than 78%.

If attendance is below 78%, the function returns 1 indicating the student is a defaulter with short attendance. Otherwise, it returns 0 indicating attendance is not short.

The main program accepts inputs from the user, calls the function, and displays an appropriate message based on the returned value.

Exercise: CASE STUDY-BASED QUESTION | Q: 2 | (Chapter: 31)
For More Understanding

Explanation

This question from the NCERT textbook asks students to create a user-defined function for attendance checking. The function must accept working days, calculate attendance percentage using the given formula, and return 1 or 0 based on the 78% threshold. The solution demonstrates proper function definition, parameter passing, conditional logic, and return statements as expected in the Class 11 Python curriculum.

Solution Steps

  1. Step 1: Define function with parameters for working days and days present

  2. Step 2: Calculate attendance percentage using formula: (daysPresent / workingDays) * 100

  3. Step 3: Use if-else to check if attendance < 78%

  4. Step 4: Return 1 if short attendance, else return 0

  5. Step 5: Write main program to accept inputs and call function