1
#python game

import random

a = random.randint(1,100)

b = int (input("guess the number"))

while True :

    if a == b:
        print ("you guessed it correct \n you won the game!!")
        break
        
    elif a>= b:
        print ("you guesssed it too high")
        
    else :
        print ('you guessed it too low')
1
  • You have to get the input in the loop rather than before the loop. Commented Sep 22, 2020 at 17:37

2 Answers 2

1

You have to get the input in the loop rather than before the loop:

a = random.randint(1,100)

# b = int (input("guess the number")) <--- DELETE

while True :

    b = int (input("guess the number")) # <--- INSERT

    if a == b:
        print ("you guessed it correct \n you won the game!!")
        break        
    elif a >= b:
        print ("you guesssed it too high")        
    else:
        print ('you guessed it too low')
Sign up to request clarification or add additional context in comments.

Comments

1

Put the input in the loop.

import random

a = random.randint(1,100)

while True :
    b = int (input("guess the number"))
    if a == b:
        print ("you guessed it correct \n you won the game!!")
        break

    elif a>= b:
        print ("you guesssed it too high")

    else :
        print ('you guessed it too low')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.