-1

I am writing a code for a basic guessing game where the user guess a number this is my current code.

x = int(input())
import random
num = random.randrange(0, 100)
if x > num:
    print("Too high!")
if x < num:
    print("Too low!")
if x == num:
    print("Correct!")

I have tried to make the input a function instead and inserting it into a while loop. Along with trying to simply use more inputs but it won't print the result until after both inputs are entered. How do I make the user-input change while the code is running?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • It's a bit unclear what you're asking. Can you write out an example of what your desired output should be? – blackbrandt Mar 11 '21 at 18:37
  • I reckon the OP wants to learn about the `while` loop. – baduker Mar 11 '21 at 18:38
  • Should probably be closed as duplicate of [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response). – martineau Mar 11 '21 at 18:56

1 Answers1

0

Is this what you're trying to do?

flag = False

import random
randomNum = random.randrange(0,100)

while not flag:
    x = int(input())

    print("Cheat ", randomNum)
    if randomNum > x :
        print("Too Low")
    elif randomNum < x:
        print("Too High")
    else:
        print("Correct")
        flag = True
Bibek Bhandari
  • 422
  • 1
  • 4
  • 15