- #1
- 7,010
- 10,470
- TL;DR Summary
- Want to loop using various conditions.
Hi all,
Trying to right a program in Python asking user to guess a number ( integer in finite range) until they make a correct guess, though I want to warn user when guess is too high --asking that they choose a lower number ,and same for when the guess is low, asking them to choose a higher number ,and ultimately pointing out when the guess is correct. I would like suggestions for the specific data structures to do this.
I have written a program that runs, prompting the user to guess until they guess correctly or exiting after a certain number of tries, using while loops and a counter variable that increases by 1 upon each guess.
Problem comes in designing a loop that goes back-and-forth between " overshoots (guess is too high)" and "undershoots( guess is too low)" until they guess the correct number ,whereby program exits:
Say the number is 10: If user enters , day, 9, they will be prompted to guess higher. But if they then choose , say, 11 and overshoot, how can I then prompt them to go back to guessing lower? Is there something along the lines of a" Go To" in Python? Maybe something else?Any ideas on how to go about doing this?
Trying to right a program in Python asking user to guess a number ( integer in finite range) until they make a correct guess, though I want to warn user when guess is too high --asking that they choose a lower number ,and same for when the guess is low, asking them to choose a higher number ,and ultimately pointing out when the guess is correct. I would like suggestions for the specific data structures to do this.
I have written a program that runs, prompting the user to guess until they guess correctly or exiting after a certain number of tries, using while loops and a counter variable that increases by 1 upon each guess.
Problem comes in designing a loop that goes back-and-forth between " overshoots (guess is too high)" and "undershoots( guess is too low)" until they guess the correct number ,whereby program exits:
Say the number is 10: If user enters , day, 9, they will be prompted to guess higher. But if they then choose , say, 11 and overshoot, how can I then prompt them to go back to guessing lower? Is there something along the lines of a" Go To" in Python? Maybe something else?Any ideas on how to go about doing this?