Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pickle as p
- def create():
- n = int(input("Enter no of records: "))
- f = open('Attendance.dat', 'wb')
- for k in range(n):
- name = input("Enter name: ")
- admn = int(input("Enter admn no: "))
- ndp = int(input("Enter no of present days: "))
- tdp = 200 #Setting no of working days to a default value as total no of working days does not change
- # tdp = int(input("Enter total no of days")) # Not necessary when setting a default value
- L = [name, admn, ndp, tdp]
- p.dump(L, f)
- f.close()
- print("File Created")
- def tabular():
- f = open("Attendance.dat", 'rb')
- print("{:<20}".format("Name"), "{:<20}".format("Admno"), "{:<20}".format("No of working days"), "{:<20}".format("Total working days"))
- while True:
- try:
- A = p.load(f)
- for k in A:
- print("{:<20}".format(k), end=" ")
- print()
- except EOFError:
- break
- f.close()
- def detail75():
- f = open('Attendance.dat', 'rb')
- print("{:<20}".format("Name"), "{:<20}".format("Admno"), "{:<20}".format("No of working days"), "{:<20}".format("Total working days"))
- while True:
- try:
- A = p.load(f)
- per = (A[2]/A[3]) * 100
- if per < 75:
- for k in A:
- print("{:<20}".format(k), end=" ")
- print()
- except EOFError:
- break
- f.close()
- def count75():
- f = open("Attendance.dat", 'rb')
- count = 0
- while True:
- try:
- A = p.load(f)
- per = (A[2]/A[3]) * 100
- if per > 75:
- count = count + 1
- except EOFError:
- break
- f.close()
- print("No of students with more than 75% attendance: ",count)
- while True:
- print("\t\t\t1. Create a binary file")
- print("\t\t\t2. Display the content in tabular form")
- print("\t\t\t3. Display the details of the student whose attendace is below 75%")
- print("\t\t\t4. Display the total no of students whose attendance is above 75%")
- print("\t\t\t5. Kill the program")
- ch = int(input("\t\t\tEnter your selection: "))
- if ch == 1:
- create()
- elif ch == 2:
- tabular()
- elif ch == 3:
- detail75()
- elif ch == 4:
- count75()
- elif ch == 5:
- print("Thank you for using me")
- break
- else:
- print("Invalid option, Please try again")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement