First off your code never even import random
to use randint
. But I'll assume you did import it and you just never pasted it in.
input
reads your input as a str
, but you want it to read as an int
. All you really need to do is wrap the input()
call in an int
invocation. Additionally, input
takes an argument, which prompts that argument in the console.
Also @tobias_k has a good point, but instead of elif guess == answer:
, just use else:
.
I also changed some variable logic, and I changed A
to a much more meaningful identifier, as well as fixing formatting, like a = b
is more aesthetically pleasing than a=b
.
Oh and indentation. Indentation is important, not only for readability, but in Python, it's required. Python is whitespace significant, meaning scope delimiters are whitespace.
import random
finished_count = 0
while finished_count < 10:
for _ in range(5):
answer = random.randint(1, 5)
guess = int(input("Ralph holds up %d finger%s. What is the answer?\n" % (answer, "" if answer == 1 else "s")))
if guess != answer: # incorrect answer
print("WRONG PROGRESS RESET")
finished_count = 0
else: # correct
finished_count += 1
print("Correct. You have %d out of 10 finished" % finished_count)
print("You win, congrats!")
I just used this code up until I got to 10 and it works fine