|
1 | 1 | """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”. |
3 | 3 | Structure of record is [roll number, name, percentage]. His computer |
4 | 4 | teacher has assigned the following duty to Amit |
5 | 5 |
|
6 | 6 | Write a function remcount( ) to count the number of students who need |
7 | 7 | remedial class (student who scored less than 40 percent) |
| 8 | +and find the top students of the class. |
8 | 9 |
|
9 | | -
|
| 10 | +We have to find weak students and bright students. |
10 | 11 | """ |
11 | | -# also find no. of children who got top marks |
| 12 | + |
| 13 | +## Find bright students and weak students |
| 14 | + |
| 15 | +from dotenv import load_dotenv |
| 16 | +import os |
| 17 | + |
| 18 | +base = os.path.dirname(__file__) |
| 19 | +load_dotenv(os.path.join(base, ".env")) |
| 20 | +student_record = os.getenv("STUDENTS_RECORD_FILE") |
12 | 21 |
|
13 | 22 | import pickle |
| 23 | +import logging |
| 24 | + |
| 25 | +# Define logger with info |
| 26 | +# import polar |
14 | 27 |
|
15 | | -list = [ |
16 | | - [1, "Ramya", 30], |
17 | | - [2, "vaishnavi", 60], |
18 | | - [3, "anuya", 40], |
19 | | - [4, "kamala", 30], |
20 | | - [5, "anuraag", 10], |
21 | | - [6, "Reshi", 77], |
22 | | - [7, "Biancaa.R", 100], |
23 | | - [8, "sandhya", 65], |
24 | | -] |
25 | 28 |
|
26 | | -with open("class.dat", "ab") as F: |
27 | | - pickle.dump(list, F) |
28 | | - F.close() |
| 29 | +## ! Unoptimised rehne de abhi ke liye |
29 | 30 |
|
30 | 31 |
|
31 | 32 | def remcount(): |
32 | | - with open("class.dat", "rb") as F: |
| 33 | + with open(student_record, "rb") as F: |
33 | 34 | val = pickle.load(F) |
34 | 35 | count = 0 |
| 36 | + weak_students = [] |
35 | 37 |
|
36 | | - for i in val: |
37 | | - if i[2] <= 40: |
38 | | - print(f"{i} eligible for remedial") |
| 38 | + for student in val: |
| 39 | + if student[2] <= 40: |
| 40 | + print(f"{student} eligible for remedial") |
| 41 | + weak_students.append(student) |
39 | 42 | count += 1 |
40 | | - print(f"the total number of students are {count}") |
| 43 | + print(f"the total number of weak students are {count}") |
| 44 | + print(f"The weak students are {weak_students}") |
41 | 45 |
|
42 | | - |
43 | | -remcount() |
| 46 | + # ! highest marks is the key here first marks |
44 | 47 |
|
45 | 48 |
|
46 | 49 | def firstmark(): |
47 | | - with open("class.dat", "rb") as F: |
| 50 | + with open(student_record, "rb") as F: |
48 | 51 | val = pickle.load(F) |
49 | 52 | count = 0 |
50 | 53 | main = [i[2] for i in val] |
51 | 54 |
|
52 | 55 | top = max(main) |
53 | 56 | print(top, "is the first mark") |
54 | 57 |
|
55 | | - F.seek(0) |
56 | 58 | for i in val: |
57 | 59 | if top == i[2]: |
58 | 60 | print(f"{i}\ncongrats") |
59 | 61 | count += 1 |
60 | | - |
61 | | - print("the total number of students who secured top marks are", count) |
| 62 | + print("The total number of students who secured top marks are", count) |
62 | 63 |
|
63 | 64 |
|
| 65 | +remcount() |
64 | 66 | firstmark() |
65 | | - |
66 | | -with open("class.dat", "rb") as F: |
67 | | - val = pickle.load(F) |
68 | | - print(val) |
0 commit comments