So, I'm trying to make a python program that needs to substitute a value in a python 2d array, but somehow it isn't working correctly, giving me results like:
[0, M, 0, M]
[0, M, 0, M]
[0, M, 0, M]
[0, M, 0, M]
when it's supposed to grant me results like:
[0, 0, 0, M]
[0, M, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
Please, if someone could explain to me what causes the error, I would be really thankful.
import random
import sys
import os
def genwmap(minv, maxv, mode):
wmap = []
temp = []
mx = random.randint(minv, maxv)
my = random.randint(minv, maxv)
for element in range(0, mx):
temp.append("0")
for element in range(0, my):
wmap.append(temp)
temp = random.randint(int(minv*maxv/15), int(minv*maxv/5)) #Use temp var to generate region's count
if mode == 1:
for element in range(0, temp):
one = random.randint(0, len(wmap)-1)
two = random.randint(0, len(wmap[0])-1)
wmap[one][two] = "M"
for element in wmap:
print(element)
print(wmap[1][1])
print("one: " + str(one))
print("two: " + str(two))
return wmap
r = genwmap(10, 20, 1)
for element in r:
print(element)