Very basic question. How do I start again?

Chris Angelico rosuav at gmail.com
Thu Aug 21 21:58:00 EDT 2014


On Fri, Aug 22, 2014 at 11:37 AM, Seymore4Head
<Seymore4Head at hotmail.invalid> wrote:
> I want to give the computer 100 tries to guess a random number between
> 1 and 100 picked by the computer.
>

Suggestion: Be up-front about this being a homework assignment. Most
of us can tell anyway, and it's more honest that way :)

So, since this is homework, I'm not going to give you the answer. What
I'll do is point you in the direction you need to go.

The most important problem isn't in your code, it's actually here:

> The program fails when guess=pick

In Python, a program doesn't simply fail. It might do the wrong thing
(in which case you should tell us both what it does and what you
expect it to do), or it might terminate with an exception traceback.
Those tracebacks are incredibly useful; when you're asking for help
with a failing program, pasting the entire traceback, including the
full error message, is extremely helpful.

In this case, though, what I'm seeing is that the program will
errantly keep looping when it gets it right. (Not infinitely as you
have the "count < 100" check, but it still loops more than it should.)
So what you need to do is tell it to stop looping when it gets the
right guess. Do you know how to do that?

ChrisA



More information about the Python-list mailing list