Home > Net >  Whenever I try to run this number guessing program, I cannot figure out a way to define 'numb&#
Whenever I try to run this number guessing program, I cannot figure out a way to define 'numb&#

Time:12-21

print("Guess the Number between 1 and 5, no win, 2v21")
geological = random.randint(1, 5)
holborn = False
Score = 0

if holborn == True:
    Score  = 1

while holborn == False:

    numb == int(input("Enter a number: "))
if numb == geological:
    print("Correct.")
    holborn == True
else:
    print("Incorrect.")

Tried turning numb into a boolean value, which infinitely loops the first line of the actual game until I break it. Setting it to true or false does not work either. Tried making a class for it, but it didn't work either. I need help.

CodePudding user response:

Here, is the code snippet which works.

import random
print("Guess the Number between 1 and 5, no win, 2v21")
geological = random.randint(1, 5)

holborn = False
Score = 0
numb = 0

if holborn == True:
    Score  = 1

while holborn == False:
    numb = int(input("Enter a number: "))
    if numb == geological:
        print("Correct.")
        holborn = True
    else:
        print("Incorrect.")

Two issues that I found in the code is:

  1. The if-else statement should be in while loop.
  2. While writing this numb == int(input("Enter a number: ")) you are using == whereas for assigning the value it should be =
  3. the Same thing, is missing while holborn == True it should be single =

I hope this helps.

CodePudding user response:

numb == int(input("Enter a number: "))
holborn == True

These lines should use =, not ==.

= is assignment. == is comparison.

Also:

while holborn == False:

    numb == int(input("Enter a number: "))
if numb == geological:
    print("Correct.")
    holborn == True
else:
    print("Incorrect.")

If this is the actual indentation from your program, then the while loop will be infinite, because holborn never changes as part of the loop. numb == int(input("Enter a number: ")) is the only code that is actually part of the loop.

  • Related