Check for a particular command in a students response.

Check for a particular command in a students response.

by Levi Osborne -
Number of replies: 3

I am writing a very simple quiz for my students learning python about loops. The questions are very basic, like write a code that uses a while loop to print the number 1-10. However, I want to make sure that they use a while loop and don't just use 10 prints. Is there a way to check the students code for the while command and fail the question if while is not present?

In reply to Levi Osborne

Re: Check for a particular command in a students response.

by Richard Lobb -
In reply to Richard Lobb

Re: Check for a particular command in a students response.

by Levi Osborne -
This is awesome! Thank you so much exactly what I needed. 

If I wanted to make sure there was a command in the answer (The opposite of the video) I would use something like this instead correct?

if not 'while' in __student_answer__:
    print("You must use a while loop for credit!", file=sys.stderr)
    sys.exit(1)