Help with arrays

Gleb Belov gbelov at gmail.com
Tue Aug 25 18:14:26 EDT 2009


Hello! I'm working on an exercise wherein I have to write a Guess The
Number game, but it's the computer who's guessing MY number. I can get
it to work, but there's one obvious problem: the computer generates
random numbers until one of them corresponds to my number, but it will
often generate one number (eg. 4) numerous times, meaning it doesn't
know that this number is invalid. What I mean is, it will sometimes
use 37 tries to guess a number out of 1 - 9, which makes no sense,
since it should only take 9 tries, at most. I was trying to find a way
to make a dynamic list of all the numbers the computer generates in
the loop and then make it re-generate the number if the previous
number is present in the list, so it doesn't keep on generating 4 (as
an example). I don't know if that makes sense... Basically, we humans
know that once something is incorrect, there's no point in trying to
use it as the answer next time, because we already know it's
incorrect. How do I go about coding this in Python? I'm still quite
new to the language so any help will be appreciated...



More information about the Python-list mailing list