Skip to content

Commit ee0d637

Browse files
some corrections
1 parent 094541f commit ee0d637

File tree

2 files changed

+38
-41
lines changed

2 files changed

+38
-41
lines changed
Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,67 @@
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”.
33
Structure of record is [roll number, name, percentage]. His computer
44
teacher has assigned the following duty to Amit
55
66
Write 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

1423
import 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

3333
def 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+
4851
def 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}\ncongrats")
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()

1 File handle/File handle binary/search record in binary file.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# binary file to search a given record
22

33
import pickle
4+
from dotenv import load_dotenv
45

5-
6-
def binary_search():
7-
with open("studrec.dat", "rb") as F:
6+
def search():
7+
with open("student_records.pkl", "rb") as F:
88
# your file path will be different
9-
search = 0
9+
search = True
1010
rno = int(input("Enter the roll number of the student"))
1111

1212
for i in pickle.load(F):
1313
if i[0] == rno:
1414
print(f"Record found successfully\n{i}")
15-
search = 1
15+
search = False
1616

17-
if search == 0:
17+
if search:
1818
print("Sorry! record not found")
1919

2020

0 commit comments

Comments
 (0)