[Tutor] guess my number game

Mats Wichmann mats at wichmann.us
Tue May 8 10:12:20 EDT 2018

On 05/08/2018 06:04 AM, Jan Erik Moström wrote:
>> Here is the code with the while loop
>> import random
>> n = (random.randint(0,100))
>> g = int(input('Guess my number, 0 to 100, you have 10 chances'))

you should get your students into good programming habits right away.
Here you are taking data from outside the program's own control, and in
the current terminology that data is "tainted" until you validate it -
there should be a check that you got back a number in the range that you
specify.  Yes in this simple example you don't do anything with the
guess that could be harmful, but they should still be learning to keep
such considerations in mind.

More information about the Tutor mailing list