Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guess a number
#2
Welcome to the Python forum,

A small script like yours does not have to be a function.

See the following link for use of a while loop. http://www.pythonforbeginners.com/contro...hile-loops
Seed the value outside of the loop, and then loop until an answer is obtained. Use an input() statement to get the guess from the user.

Additional items to consider after you are successful:
a. What if the user types in something other than a number?
b. What if the user wants to give up?


Please let us know if you need additional help.

Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply


Messages In This Thread
Guess a number - by Ameen - Apr-02-2018, 01:03 AM
RE: Guess a number - by ljmetzger - Apr-02-2018, 09:22 PM
RE: Guess a number - by Ares - Apr-03-2018, 01:50 AM
RE: Guess a number - by scidam - Apr-03-2018, 03:35 AM
RE: Guess a number - by sylas - Apr-03-2018, 07:28 AM
RE: Guess a number - by snippsat - Apr-03-2018, 01:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess the word game help jackthechampion 3 3,140 Sep-06-2023, 06:51 AM
Last Post: Pedroski55
  Ask again if wrong guess with While. EduPy 4 2,367 Oct-21-2021, 07:46 PM
Last Post: menator01
  I guess it's about print tsavoSG 2 2,208 Feb-08-2021, 08:34 PM
Last Post: steve_shambles
  can't figure out problem with number guess Galoxys 4 3,445 Oct-29-2018, 01:45 PM
Last Post: snippsat
  Guess Random Number Why i m not able to enter input Nithya Thiyagarajan 6 8,358 Jan-07-2018, 04:26 AM
Last Post: squenson
  "Guess the Number" game CTT 14 13,639 Jul-26-2017, 11:41 AM
Last Post: sylas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020