Advertisement
ALENTL

main.py

Jul 26th, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.52 KB | None | 0 0
  1. import pickle as p
  2.  
  3. def create():
  4.     n = int(input("Enter no of records: "))
  5.     f = open('Attendance.dat', 'wb')
  6.  
  7.     for k in range(n):
  8.         name = input("Enter name: ")
  9.         admn = int(input("Enter admn no: "))
  10.         ndp = int(input("Enter no of present days: "))
  11.         tdp = 200 #Setting no of working days to a default value as total no of working days does not change
  12.         # tdp = int(input("Enter total no of days")) # Not necessary when setting a default value
  13.  
  14.         L = [name, admn, ndp, tdp]
  15.  
  16.         p.dump(L, f)
  17.  
  18.     f.close()
  19.     print("File Created")
  20.  
  21. def tabular():
  22.     f = open("Attendance.dat", 'rb')
  23.     print("{:<20}".format("Name"), "{:<20}".format("Admno"), "{:<20}".format("No of working days"), "{:<20}".format("Total working days"))
  24.  
  25.     while True:
  26.         try:
  27.             A = p.load(f)
  28.            
  29.             for k in A:
  30.                 print("{:<20}".format(k), end=" ")
  31.             print()
  32.  
  33.         except EOFError:
  34.             break
  35.    
  36.     f.close()
  37.  
  38. def detail75():
  39.     f = open('Attendance.dat', 'rb')
  40.     print("{:<20}".format("Name"), "{:<20}".format("Admno"), "{:<20}".format("No of working days"), "{:<20}".format("Total working days"))
  41.  
  42.     while True:
  43.         try:
  44.             A = p.load(f)
  45.  
  46.             per = (A[2]/A[3]) * 100
  47.  
  48.             if per < 75:
  49.                 for k in A:
  50.                     print("{:<20}".format(k), end=" ")
  51.                 print()
  52.         except EOFError:
  53.             break
  54.    
  55.     f.close()
  56.  
  57. def count75():
  58.     f = open("Attendance.dat", 'rb')
  59.     count = 0
  60.  
  61.     while True:
  62.         try:
  63.             A = p.load(f)
  64.  
  65.             per = (A[2]/A[3]) * 100
  66.  
  67.             if per > 75:
  68.                 count = count + 1
  69.         except EOFError:
  70.             break
  71.  
  72.     f.close()
  73.     print("No of students with more than 75% attendance: ",count)
  74.  
  75. while True:
  76.     print("\t\t\t1. Create a binary file")
  77.     print("\t\t\t2. Display the content in tabular form")
  78.     print("\t\t\t3. Display the details of the student whose attendace is below 75%")
  79.     print("\t\t\t4. Display the total no of students whose attendance is above 75%")
  80.     print("\t\t\t5. Kill the program")
  81.  
  82.     ch = int(input("\t\t\tEnter your selection: "))
  83.  
  84.     if ch == 1:
  85.         create()
  86.  
  87.     elif ch == 2:
  88.         tabular()
  89.  
  90.     elif ch == 3:
  91.         detail75()
  92.  
  93.     elif ch == 4:
  94.         count75()
  95.  
  96.     elif ch == 5:
  97.         print("Thank you for using me")
  98.         break
  99.  
  100.     else:
  101.         print("Invalid option, Please try again")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement