Apr-07-2021, 04:48 PM
I'm totally new to python.
I'm writing a simple code that is supposed to find random bingo statistics. The code works just fine until I'm trying to run it more than once in a for loop. Forget about the code, just check out the oldmatrix variable. I never set a new value to it and yet it changes on the second iteration. How can it be??
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
import random
print("Hello world")
bingo = 0
checkbingo = 0
basematrix = [[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]
matrix = [[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]
baselist = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
list = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
for iter in range(2):
print("ïter =", iter)
print("basematrix = ", basematrix)
print("matrix = ",matrix)
#random punch
for punchnum in range(25):
n = random.randint(0, len(list)-1)
i = list[n]
matrix[round((i-i%5)/5)][round(i%5)] = 1
list.pop(n)
#check bingo
for x in range(5):
for y in range(5):
checkbingo = checkbingo + (matrix[x][y])
if checkbingo == 5:
bingo = 1
checkbingo = 0
if bingo == 0:
for y in range(5):
for x in range(5):
checkbingo = checkbingo + (matrix[x][y])
if checkbingo == 5:
bingo = 1
checkbingo = 0
print(punchnum," = ", bingo)
print("basematrix = ", basematrix)
matrix = basematrix
print("matrix = ",matrix)
list = baselist
I'm writing a simple code that is supposed to find random bingo statistics. The code works just fine until I'm trying to run it more than once in a for loop. Forget about the code, just check out the oldmatrix variable. I never set a new value to it and yet it changes on the second iteration. How can it be??
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
import random
print("Hello world")
bingo = 0
checkbingo = 0
basematrix = [[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]
matrix = [[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]
baselist = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
list = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
for iter in range(2):
print("ïter =", iter)
print("basematrix = ", basematrix)
print("matrix = ",matrix)
#random punch
for punchnum in range(25):
n = random.randint(0, len(list)-1)
i = list[n]
matrix[round((i-i%5)/5)][round(i%5)] = 1
list.pop(n)
#check bingo
for x in range(5):
for y in range(5):
checkbingo = checkbingo + (matrix[x][y])
if checkbingo == 5:
bingo = 1
checkbingo = 0
if bingo == 0:
for y in range(5):
for x in range(5):
checkbingo = checkbingo + (matrix[x][y])
if checkbingo == 5:
bingo = 1
checkbingo = 0
print(punchnum," = ", bingo)
print("basematrix = ", basematrix)
matrix = basematrix
print("matrix = ",matrix)
list = baselist