Feb-25-2020, 09:45 PM
I am trying to write a short program to solve a measurement puzzle with three jiggers of water. I want it to loop through a list of tuples, each one of which describes a pouring jigger and a receiving jigger by its size and its content. After running through the for loop once in which a function modifies the jigger contents, I want to be able to reset the jigger to its original contents and run through the for loop a second time. I do not seem to be able to reset the contents of the jigger to its original state for the second run through the for loop.
# oneLiterPourSolver_test.py # figures out a classic 3 jigger pour puzzle jigger3 = [3,2] jigger5 = [5,3] jigger8 = [8,5] pour_1 = [(jigger3,jigger5),(jigger3, jigger8)] def resetJiggers(): global jigger3, jigger5, jigger8, pour_1 jigger3 = [3,2] jigger5 = [5,3] jigger8 = [8,5] # [(pour from 3 into 5),(pour from 3 into 8)] pour_1 = [(jigger3,jigger5),(jigger3, jigger8)] def firstPour(fromJigger, toJigger): toJigger[1] = toJigger[1] + fromJigger[1] fromJigger[1] = 0 for (x,y) in pour_1: firstPour(x,y) resetJiggers()I know I'm missing something very simple. I've tried using globals (everywhere!) AND moving the call to resetJiggers() to different position, all to no avail. My debugger (in IDLE) indicates that, once called, the for loop uses the changed values of jigger3 and jigger5 (instead of the reset values) no matter what...