|
| 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 “student_records.pkl”. |
| 3 | +Structure of record is [roll number, name, percentage]. His computer |
| 4 | +teacher has assigned the following duty to Amit |
| 5 | +
|
| 6 | +Write a function remcount( ) to count the number of students who need |
| 7 | + remedial class (student who scored less than 40 percent) |
| 8 | +and find the top students of the class. |
| 9 | +
|
| 10 | +We have to find weak students and bright students. |
| 11 | +""" |
| 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") |
| 21 | + |
| 22 | +import pickle |
| 23 | +import logging |
| 24 | + |
| 25 | +# Define logger with info |
| 26 | +# import polar |
| 27 | + |
| 28 | + |
| 29 | +## ! Unoptimised rehne de abhi ke liye |
| 30 | + |
| 31 | + |
| 32 | +def remcount(): |
| 33 | + with open(student_record, "rb") as F: |
| 34 | + val = pickle.load(F) |
| 35 | + count = 0 |
| 36 | + weak_students = [] |
| 37 | + |
| 38 | + for student in val: |
| 39 | + if student[2] <= 40: |
| 40 | + print(f"{student} eligible for remedial") |
| 41 | + weak_students.append(student) |
| 42 | + count += 1 |
| 43 | + print(f"the total number of weak students are {count}") |
| 44 | + print(f"The weak students are {weak_students}") |
| 45 | + |
| 46 | + # ! highest marks is the key here first marks |
| 47 | + |
| 48 | + |
| 49 | +def firstmark(): |
| 50 | + with open(student_record, "rb") as F: |
| 51 | + val = pickle.load(F) |
| 52 | + count = 0 |
| 53 | + main = [i[2] for i in val] |
| 54 | + |
| 55 | + top = max(main) |
| 56 | + print(top, "is the first mark") |
| 57 | + |
| 58 | + for i in val: |
| 59 | + if top == i[2]: |
| 60 | + print(f"{i}\ncongrats") |
| 61 | + count += 1 |
| 62 | + print("The total number of students who secured top marks are", count) |
| 63 | + |
| 64 | + |
| 65 | +remcount() |
| 66 | +firstmark() |
0 commit comments