I have created an simple, arbritrary function that prints out a value (1) based on what the first element from a randomly shuffled list is.
Looking at the code below: I am creating a variable and setting it to 1, then I'm a creating a small list (1,2,3) and then shuffling the list. The idea is, if the first element of that list (after shuffle) is 1 or 2, then print the value of 'correct', BUT if the first element of the list happens to be 3, set 'correct' to 0, and then run the function again. As you can see from the if statement, when 'value' is set to 0, I don't expect this to be printed at all because the function is being run again (chair()) before any printing takes place.
Having run this, I expected to find a print out of 5 values of 1. The problem is, I am seeing 0 values printed too. This seems like a very simple function, and I feel a little but stupid for not seeing why this is happenig. Any ideas?
def chair():
correct = 1
a = [1,2,3]
random.shuffle(a)
if a[0] == 3:
correct = 0
chair() #run function again without printing
print correct
for i in range(5):
chair()