mystery.py
# Practice with 2D lists
# by Sara Sprenkle
def main():
matrix = createMatrix()
print("Before:")
print(matrix)
mystery(matrix)
print("After:")
print(matrix)
def mystery(a):
""" "run" this on A, at right """
for row in range( len(a) ):
for col in range( len(a[0]) ):
if row == col:
a[row][col] = 42
else:
a[row][col] += 1
def createMatrix():
a0 = list(range(1,5))
a1 = list(range(5,9))
a2 = list(range(9,13))
a = []
a.append(a0)
a.append(a1)
a.append(a2)
return a
main()
Generated by GNU enscript 1.6.4.