11"""Amit is a monitor of class XII-A and he stored the record of all
2- the students of his class in a file named “class.dat ”.
2+ the students of his class in a file named “student_records.pkl ”.
33Structure of record is [roll number, name, percentage]. His computer
44teacher has assigned the following duty to Amit
55
66Write a function remcount( ) to count the number of students who need
77 remedial class (student who scored less than 40 percent)
8+ and find the top students of the class.
89
9-
10+ We have to find weak students and bright students.
1011"""
1112
12- # also find no. of children who got top marks
13+
14+ ## Find bright students and weak students
15+
16+ from dotenv import load_dotenv
17+ import os
18+
19+ base = os .path .dirname (__file__ )
20+ load_dotenv (os .path .join (base , ".env" ))
21+ student_record = os .getenv ("STUDENTS_RECORD_FILE" )
1322
1423import pickle
24+ import logging
1525
16- # ! Making a generator would be lovely a fake data generator for testing purposes
17- list = [
18- [1 , "Ramya" , 30 ],
19- [2 , "vaishnavi" , 60 ],
20- [3 , "anuya" , 40 ],
21- [4 , "kamala" , 30 ],
22- [5 , "anuraag" , 10 ],
23- [6 , "Reshi" , 77 ],
24- [7 , "Biancaa.R" , 100 ],
25- [8 , "sandhya" , 65 ],
26- ]
26+ # Define logger with info
27+ # import polar
2728
28- with open ("class.dat" , "ab" ) as F :
29- pickle .dump (list , F )
30- F .close ()
29+
30+ ## ! Unoptimised rehne de abhi ke liye
3131
3232
3333def remcount ():
34- with open ("class.dat" , "rb" ) as F :
34+ with open (student_record , "rb" ) as F :
3535 val = pickle .load (F )
3636 count = 0
37+ weak_students = []
38+
3739
38- for i in val :
39- if i [2 ] <= 40 :
40- print (f"{ i } eligible for remedial" )
40+ for student in val :
41+ if student [2 ] <= 40 :
42+ print (f"{ student } eligible for remedial" )
43+ weak_students .append (student )
4144 count += 1
42- print (f"the total number of students are { count } " )
43-
44-
45- remcount ()
45+ print (f"the total number of weak students are { count } " )
46+ print (f"The weak students are { weak_students } " )
4647
4748
49+ # ! highest marks is the key here first marks
50+
4851def firstmark ():
49- with open ("class.dat" , "rb" ) as F :
52+ with open (student_record , "rb" ) as F :
5053 val = pickle .load (F )
5154 count = 0
5255 main = [i [2 ] for i in val ]
5356
5457 top = max (main )
5558 print (top , "is the first mark" )
5659
57- F .seek (0 )
5860 for i in val :
5961 if top == i [2 ]:
6062 print (f"{ i } \n congrats" )
6163 count += 1
64+ print ("The total number of students who secured top marks are" , count )
6265
63- print ("the total number of students who secured top marks are" , count )
64-
65-
66- firstmark ()
67-
68- with open ("class.dat" , "rb" ) as F :
69- val = pickle .load (F )
70- print (val )
66+ remcount ()
67+ firstmark ()
0 commit comments