# Python - stuck with a simple program

**URL:** <https://forum.freecodecamp.org/t/python-stuck-with-a-simple-program/352731>\
**Category:** General\
**Created:** [February 23, 2020, 11:16am UTC](https://forum.freecodecamp.org/t/python-stuck-with-a-simple-program/352731 "2020-02-23T11:16:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rehantadpatri2005](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/rehantadpatri2005/32/134323_2.png) [@rehantadpatri2005](https://forum.freecodecamp.org/u/rehantadpatri2005)\
**Post date:** [February 23, 2020, 11:16am UTC](https://forum.freecodecamp.org/t/python-stuck-with-a-simple-program/352731/1 "2020-02-23T11:16:46Z")

</div>

![20200223_164138](https://global.discourse-cdn.com/freecodecamp/original/3X/8/5/8570aa401f491ab387f27d38f10919b753b20da3.jpeg)  
Well, I so I have been trying to make this ‘guessing game’ in python where the user has to guess a number based on the clues.  
But unfortunately, it doesn’t work the way I want it to.  
I want it to go like-  
1.Get single digit string from user, covert it to an integer  
2.Making sure that the number isn’t the random number to be guessed, but a loop keeps giving the user clues based on the input  
3. If the user enters the correct number, the game ends  
Please help!!

---

<div class="post-metadata">

**Author:** ![FatmaNagori](https://avatars.discourse-cdn.com/v4/letter/f/ba9def/32.png) [@FatmaNagori](https://forum.freecodecamp.org/u/FatmaNagori)\
**Post date:** [February 23, 2020, 3:14pm UTC](https://forum.freecodecamp.org/t/python-stuck-with-a-simple-program/352731/3 "2020-02-23T15:14:53Z")

</div>

you can do this by using `while True:` loop. and you don’t need `num` variable.  
import random and then generate a random number and store it in a variable as you did before i.e.

```auto
import random
guessNum=random.choice(range(1,100))

```

create a `while True:` loop  
inside the `while True :` loop take input from user i.e. `inp=input("Enter a number = ")` then use `try` to convert input into integer if user input non numeric value then use `except ` and inside `except` use `continue` statement to continue the loop. inside `try` first convert input into integer i.e. `x=int(inp)` .next check `if x>guessNum:` then `print("Higher")` and continue the loop using `continue` statement .next check `elif x<guessNum:` then `print("Lower")` and continue the loop using `continue` statement.next use `else:` statement. inside `else` condition `print('You won')` and break the ` while True:` loop using `break` statement.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 7:35pm UTC](https://forum.freecodecamp.org/t/python-stuck-with-a-simple-program/352731/4 "2021-06-01T19:35:13Z")

</div>

Closed on June 1, 2021, 7:35pm UTC


