Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

The second extra challenge on the modify task, and the hardest version of the program. The editor starts you off with the same student program as before.

Your task

Build the teacher and student program again, with the grade on the same line as the student’s name, exactly as in the previous exercise:

This time the program also validates the answer to the question about another person. It only accepts yes or no, in lower case:

There is more than one way to check the answer. You can join two comparisons with and, or check whether the answer is in a list of the answers you accept, as in the chapter on lists. Either way, the loop that does the checking goes inside the loop that is already there.

Need a hint about the second way? Click here.

The output

Each repetition starts with these questions, as before:

Enter teacher or student
Enter teacher name
Enter teacher code
Enter student name
Enter student grade

Enter teacher or student comes first, then either the two teacher questions or the two student questions. Then the question about another person:

Enter another person? yes/no

After an answer that is not accepted, these two lines, once for every such answer:

Please answer yes or no
Enter another person? yes/no

And after no, the last line:

Goodbye!

The files

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

Leo 6
Mr Price
JPR

Example

Input:

student
Ben
5
YES
yes
teacher
Mr Hughes
HUG
No
no

Output:

Enter teacher or student
Enter student name
Enter student grade
Enter another person? yes/no
Please answer yes or no
Enter another person? yes/no
Enter teacher or student
Enter teacher name
Enter teacher code
Enter another person? yes/no
Please answer yes or no
Enter another person? yes/no
Goodbye!

StudentInfo.txt afterwards:

Leo 6
Ben 5

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 answer is compared with "yes" and "no" exactly: YES, Yes and y are all different pieces of text.
  • A condition that accepts only yes or no needs both comparisons, so a while that keeps asking needs choice != "yes" and choice != "no".
  • After Please answer yes or no, the question is printed again and a new answer is read. Forget the input() and the checking loop never ends.
  • The checking loop is indented inside the main loop, after the if that writes to the files.
  • Only no sets the flag to False.