Drop links or images here to add them to the editor.

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.

Your task

Change the program so that it stores teachers and students in files of their own, exactly as in the previous exercise:

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 output

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!.

The files

StudentInfo.txt and TeacherInfo.txt might start like this:

Leo 6
Mr Price
JPR

Example

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.

Help! My code doesn't work!

Make sure that you check for the following things:

  • The name, the space and the grade are joined into one piece of text with +, and that piece of text ends with "\n".
  • There is exactly one space between the name and the grade, and none after the grade.
  • The grade is written as it was typed. It does not need int(), since nothing is calculated with it.
  • Teachers still take two lines each: the name, then the code.
  • Both files are opened in "a" mode, never "w".