An extra challenge on the previous modify task. The editor starts you off with the same student program as before, and you build the teacher and student version again, with one change to what goes into the student file.
Change the program so that it stores teachers and students in files of their own, exactly as in the previous exercise:
teacher or student.TeacherInfo.txt, each on a line of its own.StudentInfo.txt.This time, the grade is concatenated onto the line with the student’s name
before it is written. Each student becomes one line in StudentInfo.txt: the
name, a space, and then the grade.
NAME GRADE
Teachers are stored the same way as before, name and code on separate lines.
The questions are the same as in the previous exercise:
Enter teacher or student
Enter teacher name
Enter teacher code
Enter student name
Enter student grade
Enter another person? y/n
Goodbye!
Enter teacher or student starts every repetition, the two teacher questions or
the two student questions follow it, and Enter another person? y/n ends it.
Only n ends the loop, and then the program prints Goodbye!.
StudentInfo.txt and TeacherInfo.txt might start like this:
Leo 6
Mr Price
JPR
Input:
student
Ben
5
y
teacher
Mr Hughes
HUG
y
student
Dev Patel
4
n
Output:
Enter teacher or student
Enter student name
Enter student grade
Enter another person? y/n
Enter teacher or student
Enter teacher name
Enter teacher code
Enter another person? y/n
Enter teacher or student
Enter student name
Enter student grade
Enter another person? y/n
Goodbye!
StudentInfo.txt afterwards:
Leo 6
Ben 5
Dev Patel 4
TeacherInfo.txt afterwards:
Mr Price
JPR
Mr Hughes
HUG
Ask each question with its own print, and read the answer with a bare
input() on the next line, rather than passing the question to input(...).
The questions are part of the output that is checked here, so their spelling,
capital letters and punctuation count. So do the contents of both files, down
to the space between a name and a grade and the "\n" at the end of every
line.
Make sure that you check for the following things:
+,
and that piece of text ends with "\n".int(), since nothing
is calculated with it."a" mode, never "w".