Building an Attendance Tracker in Python

Aviral Srivastava Avatar

Introduction: Keeping track of attendance is crucial in various settings, whether it’s a classroom, a workplace, or any other organized gathering. In this blog post, we’ll explore how to build a simple attendance tracker using Python. We’ll go through each step of the process, from designing the user interface to implementing the functionality.

VIDEO WILL BE UPLOADED SOON HERE

1. Understanding the Problem: Before diving into the code, let’s understand the requirements of our attendance tracker. We need a program that allows users to:

  • Change the total number of days.
  • Update the number of days attended.
  • Mark today’s attendance.
  • View attendance data.
  • Exit the system.

2. Designing the User Interface: We’ll create a simple text-based menu system to interact with the user. The menu will display options for each functionality, and the user will input their choice.

# Display a welcome message to the user
print("Hi user welcome to attendance tracker")

# Continuously prompt the user for options
while True:
    # Display the menu options
    print("choose any one option\n enter 1 to change total number of days \n enter 2 to change no of days attendend \n enter 3 to marks todays present\n enter 4 to view attendance data\n enter 5 to exit")
    
    # Prompt the user for their choice
    choise = int(input("enter::"))
    
    # Option 1: Change total number of days
    if choise == 1:
        total_day = input("enter total number of days:")
        file = open("totaldays.txt", "w")  # Open file for writing
        file.write(total_day)  # Write total number of days to file
        file.close()  # Close file
        print('total days updated')  # Notify user
        
    # Option 2: Change number of days attended
    if choise == 2:
        present_day = input("enter total number of days you were present:")
        file = open("prsnt.txt", "w")  # Open file for writing
        file.write(present_day)  # Write number of days attended to file
        file.close()  # Close file
        print('present days updated')  # Notify user
        
    # Option 3: Mark today's attendance
    if choise == 3:
        file = open("prsnt.txt", "r")  # Open file for reading
        current_days = int(file.readline())  # Read current number of days attended
        new_prsnt = str(current_days + 1)  # Increment and convert to string
        file = open("prsnt.txt", "w")  # Open file for writing
        file.write(new_prsnt)  # Write new number of days attended to file
        file.close()  # Close file
        print('attendance marked and new present days:', new_prsnt)  # Notify user
        
    # Option 4: View attendance data
    if choise == 4:
        file = open("prsnt.txt", "r")  # Open attendance file for reading
        present_day = int(file.readline())  # Read number of days attended
        file.close()  # Close attendance file
        
        file = open("totaldays.txt", "r")  # Open total days file for reading
        total_day = int(file.readline())  # Read total number of days
        file.close()  # Close total days file
        
        fraction = present_day / total_day  # Calculate attendance fraction
        percent = fraction * 100  # Calculate attendance percentage
        
        # Display attendance data to user
        print("total days you were present are", present_day, '/', total_day, "\n and percentage is", percent)
        
    # Option 5: Exit the attendance system
    if choise == 5:
        print('attendance system is closed')  # Notify user
        break  # Exit the loop
#make sure to create 2 text files named totaldays and prsnt

3. Implementing the Functionality: We’ll break down the implementation into several parts:

  • Option 1: Change the total number of days: This option allows the user to input the total number of days.
  • Option 2: Change the number of days attended: Users can update the number of days they have attended.
  • Option 3: Mark today’s attendance: This option automatically increments the number of days attended for the current day.
  • Option 4: View attendance data: Users can view the total days attended and the percentage of attendance.
  • Option 5: Exit the system: Allows users to exit the program.

4. Testing and Running the Program: After writing the code, it’s essential to test the program thoroughly to ensure it works as expected. We’ll run the program and go through each option to verify its functionality

Conclusion: In this blog post, we’ve explored how to build a simple attendance tracker using Python. By following the steps outlined in this post, you can create your own attendance tracking system to suit your specific needs. Whether you’re managing a classroom, tracking employee attendance, or monitoring participation in events, this program provides a useful tool for keeping organized records.

Conatact me: sriaviralnarain@gmail.com


Leave a comment

Design a site like this with WordPress.com
Get started