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:
- The
if-else
statement should be inwhile loop
. - While writing this
numb == int(input("Enter a number: "))
you are using==
whereas for assigning the value it should be=
- 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.