Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76764
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: Very basic question. How do I start again? |
| Date | 2014-08-22 11:55 +1000 |
| References | <1e5dv9l3aik5bb1jn4vil731rdl7q6sl3l@4ax.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13268.1408672574.18130.python-list@python.org> (permalink) |
Seymore4Head <Seymore4Head@Hotmail.invalid> writes:
> The program works as expected until the computer gets a correct guess.
> I don't know what I should be doing to restart the program when
> pick=guess.
There isn't a “restart the program” code we can give. But I think you
need only something rather simpler:
> while count < 100:
> guess = random.randrange(low,high)
> print (pick, guess)
> if guess == pick:
> print ("correct")
>
> #"What I need is something here that says start over"
You can end the current loop with the ‘break’ statement. See the docs
<URL:https://docs.python.org/3/reference/simple_stmts.html#the-break-statement>
to see exactly what its semantics are, and try using that in your code.
Feel free to ask further questions when you've tried that, if it's still
not clear.
--
\ “Religious faith is the one species of human ignorance that |
`\ will not admit of even the *possibility* of correction.” —Sam |
_o__) Harris, _The End of Faith_, 2004 |
Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Very basic question. How do I start again? Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-21 21:37 -0400
Re: Very basic question. How do I start again? Ben Finney <ben+python@benfinney.id.au> - 2014-08-22 11:55 +1000
Re: Very basic question. How do I start again? Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-21 22:13 -0400
Re: Very basic question. How do I start again? Chris Angelico <rosuav@gmail.com> - 2014-08-22 12:24 +1000
Re: Very basic question. How do I start again? Chris Angelico <rosuav@gmail.com> - 2014-08-22 11:58 +1000
Re: Very basic question. How do I start again? Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-21 22:18 -0400
Re: Very basic question. How do I start again? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-08-21 23:17 -0400
Re: Very basic question. How do I start again? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-22 12:58 +1000
Re: Very basic question. How do I start again? Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-22 04:26 +0000
Re: Very basic question. How do I start again? Tim Roberts <timr@probo.com> - 2014-08-21 22:56 -0700
Re: Very basic question. How do I start again? Igor Korot <ikorot01@gmail.com> - 2014-08-21 23:21 -0700
csiph-web