First time posting here. I am a new user to Python. I am puzzled to why the list 'matrix' is changed between the two print statements (the ones with 'Hi' and 'Hi2') even though I did nothing to change it in the code. Below is the code:

- Code: Select all
`#FIRST PROPER SCRIPT`

import math

number = int(raw_input("What number do you want to input?\n"))

from random import randint

#Declaring variables

matrix = []

hold1 = [0 for x in xrange(4)]

count = 0

while (1 != 0):

count = count + 1

a = randint(0,int(math.sqrt(number)))

b = randint(0,int(math.sqrt(number)))

c = randint(0,int(math.sqrt(number)))

d = randint(0,int(math.sqrt(number)))

if ((a**2)+(b**2)+(c**2)+(d**2)) == number:

print('Hi' + str(matrix))

hold1[0] = a

hold1[1] = b

hold1[2] = c

hold1[3] = d

hold1.sort()

print('Hi2' + str(matrix))

if len(matrix) == 0:

#store

matrix.append(hold1)

Below is the output:

- Code: Select all
`What number do you want to input?`

5462

Hi[]

Hi2[]

Hi[[4, 19, 27, 66]]

Hi2[[7, 7, 42, 60]]

Hi[[7, 7, 42, 60]]

Hi2[[21, 27, 34, 56]]

Hi[[21, 27, 34, 56]]

Hi2[[7, 30, 47, 48]]

I expected each pair of Hi and Hi2 to have the exact same output. What have I done wrong?