Consider the following comma separated sample students file format (id,name,cgpa,dob,gender). Assume the file will alway
Posted: Mon Jun 06, 2022 5:42 pm
Consider the following comma separated sample students file
format (id,name,cgpa,dob,gender). Assume the file will always be
called students.txt in your source code’s file path.
1234,John Doe,1.12,22-01-1985,M
6221,Jane White,2.12,12-02-1980,F
9821,Tom Jennings,1.93,16-03-1990,M
6235,Kim Blue,1.85,15-02-2001,F
1235,Bart Simpson,2.01,19-05-1989,M
3451,Alice Wonderland,2.37,25-03-1990,F
Write a complete Python program which will perform the
following:
1. A method called
modify(stdid, field, new_value) which will modify the requested
field to the provided new value of the given student.
2. An
insert(stdid,name,cgpa,date,gender) method which will append a
student to the end of the student file.
3. A delete(stdid)
method which will delete a student record (line) completely.
4. display() which will
display all students on the monitor (tab separated).
5. A method called
stats() which will create a new file called stats.txt in the same
path of the students.txt which will contain how many female and
male students there are, the average cgpa and the total student
count on separate lines.
As a test, perform the following in the main function:
1. Display all students
on the monitor
2. Modify Tom Jennings
cgpa to 2.12
3. Add a new student
called Tom Jones with id number 2341, cgpa 3.1, date of birth
12-08-1991, gender M
4. Delete the student
Bart Simpson from the file
5. Display all students
on the monitor (this time you should see the modifications)
using Python
format (id,name,cgpa,dob,gender). Assume the file will always be
called students.txt in your source code’s file path.
1234,John Doe,1.12,22-01-1985,M
6221,Jane White,2.12,12-02-1980,F
9821,Tom Jennings,1.93,16-03-1990,M
6235,Kim Blue,1.85,15-02-2001,F
1235,Bart Simpson,2.01,19-05-1989,M
3451,Alice Wonderland,2.37,25-03-1990,F
Write a complete Python program which will perform the
following:
1. A method called
modify(stdid, field, new_value) which will modify the requested
field to the provided new value of the given student.
2. An
insert(stdid,name,cgpa,date,gender) method which will append a
student to the end of the student file.
3. A delete(stdid)
method which will delete a student record (line) completely.
4. display() which will
display all students on the monitor (tab separated).
5. A method called
stats() which will create a new file called stats.txt in the same
path of the students.txt which will contain how many female and
male students there are, the average cgpa and the total student
count on separate lines.
As a test, perform the following in the main function:
1. Display all students
on the monitor
2. Modify Tom Jennings
cgpa to 2.12
3. Add a new student
called Tom Jones with id number 2341, cgpa 3.1, date of birth
12-08-1991, gender M
4. Delete the student
Bart Simpson from the file
5. Display all students
on the monitor (this time you should see the modifications)
using Python