lundi 16 août 2021

Play random numbers and correct answers with Python [duplicate]

The computer gives me a random number and I enter the number I want and if it matches, I get a success message. But if I say the number is smaller, the computer should look for my number in a smaller range, and if I say the number is bigger, the computer should look for my number in a larger range.

I have two problems whenever I try. In the section on entering the answer, I would fall into the trap of infinity and how to tell the computer to give a random number in a smaller interval than the previous suggested number. I must do this while loop and they did not tell me anything about binaries

import random

guess = random.randint(1,100)

print(guess)

answer = int(input())

while True:
  if answer < guess:
     print("Number Is Smaller")
     hads = random.randint(1,50)
  elif answer > guess:
       print("Number Is Bigger")
       hads = random.randint(50,100)
  else:
        print("Great")
        break



Aucun commentaire:

Enregistrer un commentaire