Simple number guessing game in python The problem is to ask the user to guess a number between 1 to 100 and compare it with a random number of that range. If user guessed number is lesser/greater than the random number print &quot;too low&quot; or &quot;too high&quot; accordingly. Take new input asking the user to guess the correct number again. When the guessed number matches with the random number print &quot;you win&quot; and the number of attempts the user required to guess it.
import random
u_num = int(input(&quot;guess a number between 1 to 100: &quot;))
w_num = random.randint(1,100)
i = 1
while u_num != w_num:
    if u_num &lt; w_num:
        print(&quot;too low&quot;)
    else:
        print(&quot;too high&quot;)
    u_num = int(input(&quot;guess again: &quot;))
    i += 1
print(f&quot;you win, and you guessed this number in {i} times!&quot;)
This looks to do the job. I would only change the variable naming to be more meaningful in this context to guess for user guess and answer for the generated number.
I would also try to handle erroneous input such as strings instead of numbers being passed.
But besides this is still functionally good :D