The example here is a program in Python 3 that helps you memorize the digits of pi. I have tried using the var counter1 to show the current score, while counter2 is the score from the last round. However, I am unable to use an if statement to print how much you have improved from the last round because I am not allowed to reference counter2 after the if statement in my loop. How should this be done? I feel like there is a significant inefficiency in my code, it does not feel right at all. The ct variable was an attempt at only running the if statement if we were past the first round.
def test():
ans = (input("\nList the digits of pi! Three point... \nPi = 3."))
if (ans).isdigit() == False:print("Oops! Numbers only!")
counter1=0
for i in range(0,(len(ans))):
if ans[i] == pi[i]:
counter1+=1
else: break
next = pi[counter1:counter1+6]
if counter1==1: article=""
else: article="s"
print("\nYou got {0} digit{1}. \n\n{2}\n{3}".format(counter1, article, "3."+pi[0:counter1], (' '*(counter1+2))+next))
if counter1!=counter2 and ct!=0:
print("That's {0} more digits than the last time!".format(counter2-counter1))
inp=input("Continue? Y/N")
if inp=="N":
exit()
counter2=counter1
ct+=1
test()
ct=0
counter2=0
test()