So I am new to python and here is my python code:
def main():
N = 1
players = 10
for _ in range(N):
maxi = 0
t1 = [3, 6, 7, 5, 3, 5, 6, 2, 9, 1]
t2 = [2, 7, 0, 9, 3, 6, 0, 6, 2, 6]
for i in range(players):
count = t2[i]+1
flag = 0
def calcWin(count):
global maxi,flag
if(count in t1):
flag = 1
maxi = maxi + 1
t1.remove(count)
else:
count = count + 1
if(count<=max(t1)):
calcWin(count)
calcWin(count)
print(flag)
main()
I want the variable 'maxi' to be accessible inside the function calcWin(). So it declared the variable as global inside the function. But it throws 'NameError'. I want the variable 'maxi' to reinitialize to 0 for each 'N'. Another thing is that the 'flag' variable always prints 0 even though it satisfies the condition 'if(count in t1)'. (Note: I declared 'flag' as global inside the function). Can somebody help me with this?