-3

there is my code:

answer = input("Player 1 , Please enter your number: (1 - 100) \n") 
answer = int(answer)
is_correct = False
count = 0
while count < 10 and is_correct == False:
    guess = int(input("Player 2 Please enter you guees: \n"))
    count = count + 1
    if guess == answer:
        print("Player 2 You won!")
        is_correct = True
    elif guess < answer:
        print("Player 2 your number is smaller thean the answer !")
    elif guess > answer:
        print("Player 2 your number is greater than the answer !")

if is_correct == False:
    print("Player 2 You Lost :(")

hello I'm trying to write a guess number game but there is a bug here someone can enter a number bigger than 100 and smaller than 0 but the number should be between 0 and 100 how can I fix it?

1 Answers1

1

Add this while loop right after the second line:

while answer < 1 or answer > 100:
    answer = int(input("Player 1, Please enter your number: (1 - 100) \n"))

This will repeat asking Player 1 until he surrenders to your demands.

Michael Cao
  • 2,278
  • 1
  • 1
  • 13