Ok . Here are some general tips . Firstly lay out your code like this Start script ImportsFunctionsClasses You don ' t have anyImperative code End ScriptFunctions aren ' t called in order so its very hard to read your script when it alternates between functions and non functional imperative code . Secondly don ' t import things you aren ' t using , even if you aren ' t using them yet . Sys and OS aren ' t needed in this script . Thirdly don ' t use multi line strings to add a new line . Use n , its very confusing ! Finally consider the conditions of your while loops . If you want a script to run indefinitely then use ' while True '. In your case though you don ' t want it to run indefinitely , you want it to run until the guess is correct . The best way to do that would be to initialise a variable guess and then continually check if guess and your random number are the same . You can then keep changing the guess until its correct . Here is an example import random guess None # initialise the variable randomnumber random . randrange 1 , 11 # Generate random number while guess ! randomnumber guess intinput ' Enter a number n ' # You might want to look into handling what happens if someone enters something that can ' t be converted to an int . # put your if blocks here printguess