these are my instructions:
http://tinman.cs.gsu.edu/~raj/2010/sp10/lab6.html

this is what I have so far:

from myro import *
from random import *

def moveCell(pic1,cell1,pic2,cell2):
    x1 = 240*((cell1-1)%3)
    y1 = 240*((cell1-1)/3)
    x2 = 240*((cell2-1)%3)
    y2 = 240*((cell2-1)/3)
    for i in range(240):
        for j in range(240):
            pix1 = getPixel(pic1,x1+i,y1+j)
            r,g,b = getRGB(pix1)
            color = makeColor(r,g,b)
            setPixel(pic2,x2+i,y2+j,color)
        

def exchangeCell(pic1,cell1,pic2,cell2):
    x1 = 240*((cell1-1)%3)
    y1 = 240*((cell1-1)/3)
    x2 = 240*((cell2-1)%3)
    y2 = 240*((cell2-1)/3)
    for i in range(240):
       for j in range(240):
            pix1 = getPixel(pic1,x1+i,y1+j)
            r,g,b = getRGB(pix1)
            color = makeColor(r,g,b)
            setPixel(pic2,x2+i,y2+j,color)

def main():
    pic = makePicture("atlantaBraves.jpg")
    show(pic,"Original Picture")
    occupied = [False,False,False,False,False,False]
    scrambledPic = makePicture(720,480)
    for i in range(1,7):
        cell = input("Cell number (1-6) to exchange:")
        if cell == 0:
                break
        n = randint(1,6)
        while occupied[n-1] == True:
            n = randint(1,6)
        moveCell(pic,i,scrambledPic,n)
        occupied[n-1] = True
    show(scrambledPic,"Scrambled Picture")

the syntax is right but it still errors me and I can't see what I did wrong! I can't wait until I get a better teacher...

First of all, the assignment appears to be overdue

Secondly, I would consider using classes to define a "Piece" and a "Cell"

That might help you a lot.

the assignment was extended a week.

and in the package i have it knows what cell is.

but thank you for the bit about the piece

Oh! I'm sorry!

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in -toplevel-
    main()
  File "C:\Users\Camigirl4k3\Desktop\csc2010\Jigsaw.py", line 61, in main
    exchangeCell(pic1,cell1,pic2,cell2)
NameError: global name 'pic1' is not defined

Your error does not make sense. It is interactive shell error, not program error. What are you doing, send all data (even the myro module we have not, maybe teachers own module?)

And you have not main program in your program, so it does not execute anything.

Your error does not make sense. It is interactive shell error, not program error. What are you doing, send all data (even the myro module we have not, maybe teachers own module?)

And you have not main program in your program, so it does not execute anything.

And if you did from python command line

import Jigsaw
Jigsaw.main()

then still your error says that in this your function main has call to exchangeCell, when that function is not called anywhere.

To test it somehow I commented out the long loops and added simulation prints, I made contents of main() to become your main program. Still the program does not make sense for me.

The input of user does not seem to have any relationship of what happens. Exchange is never called.

>>> 
makePicture( atlantaBraves.jpg , None )
show( makePicture(atlantaBraves.jpg,None) , Original Picture )
makePicture( 720 , 480 )
Cell number (1-6) to exchange:2
moveCell( makePicture(atlantaBraves.jpg,None) , 1 , makePicture(720,480) , 5 ) 0 , 0 , 240 , 240
Cell number (1-6) to exchange:3
moveCell( makePicture(atlantaBraves.jpg,None) , 2 , makePicture(720,480) , 4 ) 240 , 0 , 0 , 240
Cell number (1-6) to exchange:3
moveCell( makePicture(atlantaBraves.jpg,None) , 3 , makePicture(720,480) , 3 ) 480 , 0 , 480 , 0
Cell number (1-6) to exchange:3
moveCell( makePicture(atlantaBraves.jpg,None) , 4 , makePicture(720,480) , 1 ) 0 , 240 , 0 , 0
Cell number (1-6) to exchange:3
moveCell( makePicture(atlantaBraves.jpg,None) , 5 , makePicture(720,480) , 2 ) 240 , 240 , 240 , 0
Cell number (1-6) to exchange:3
moveCell( makePicture(atlantaBraves.jpg,None) , 6 , makePicture(720,480) , 6 ) 480 , 240 , 480 , 240
show( makePicture(720,480) , Scrambled Picture )

The input of user seems to have no relationship to what happens.

##from myro import *
from random import *
def getPixel(a,b,c):
    print "getPixel(",a,',',b,',',c,')'
    return ('r','g','b')

def getRGB(a):
    print "getRGB(",a,')'
    return 'r','g','b'

def makeColor(a,b,c):
    return "Color(",a,',',b,',',c,')'

def makePicture(a,b=None):
    print "makePicture(",a,',',b,')'
    return ("makePicture("+str(a)+','+str(b)+')')

def show(a,b):
    print "show(",a,',',b,')'

def setPixel(a,b,c,d):
    print "setPixel(",a,',',b,',',c,',',d,')'

def moveCell(pic1,cell1,pic2,cell2):
    print "moveCell(",pic1,',',cell1,',',pic2,',',cell2,')',
    x1 = 240*((cell1-1)%3)
    y1 = 240*((cell1-1)/3)
    x2 = 240*((cell2-1)%3)
    y2 = 240*((cell2-1)/3)
    print x1,',',y1,',',x2,',',y2
##    for i in range(240):
##        for j in range(240):
##            pix1 = getPixel(pic1,x1+i,y1+j)
##            r,g,b = getRGB(pix1)
##            color = makeColor(r,g,b)
##            setPixel(pic2,x2+i,y2+j,color)
        

def exchangeCell(pic1,cell1,pic2,cell2):
    print "exchangeCell(",pic1,',',cell1,',',pic2,',',cell2,')',
    x1 = 240*((cell1-1)%3)
    y1 = 240*((cell1-1)/3)
    x2 = 240*((cell2-1)%3)
    y2 = 240*((cell2-1)/3)
    print x1,',',y1,',',x2,',',y2
##    for i in range(240):
##       for j in range(240):
##            pix1 = getPixel(pic1,x1+i,y1+j)
##            r,g,b = getRGB(pix1)
##            color = makeColor(r,g,b)
##            setPixel(pic2,x2+i,y2+j,color)

pic = makePicture("atlantaBraves.jpg")
show(pic,"Original Picture")
occupied = [False,False,False,False,False,False]
scrambledPic = makePicture(720,480)
for i in range(1,7):
    cell = input("Cell number (1-6) to exchange:")
    if cell == 0:
            break
    n = randint(1,6)
    while occupied[n-1] == True:  ## random cell which is unoccupied
        n = randint(1,6)
    moveCell(pic,i,scrambledPic,n)
    occupied[n-1] = True
show(scrambledPic,"Scrambled Picture")

Edited 6 Years Ago by pyTony: n/a

Little more action trace with taking first and last iterations of loops.

makePicture( atl.jpg , None ), show( mP(atl.jpg,None) , Original Picture )
makePicture( 720 , 480 ), Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 1 , mP(720,480) , 4 ), 0 , 0 , 0 , 240
gP( mP(atl.jpg,None) , 0 , 0 ) -> sP( mP(720,480) , 0 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 0 , 239 ) -> sP( mP(720,480) , 0 , 479 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 239 , 0 ) -> sP( mP(720,480) , 239 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 239 , 239 ) -> sP( mP(720,480) , 239 , 479 , ('r', 'g', 'b') )
Cell number (1-6) to exchange:2
moveCell( mP(atl.jpg,None) , 2 , mP(720,480) , 3 ), 240 , 0 , 480 , 0
gP( mP(atl.jpg,None) , 240 , 0 ) -> sP( mP(720,480) , 480 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 240 , 239 ) -> sP( mP(720,480) , 480 , 239 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 479 , 0 ) -> sP( mP(720,480) , 719 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 479 , 239 ) -> sP( mP(720,480) , 719 , 239 , ('r', 'g', 'b') )
Cell number (1-6) to exchange:3
moveCell( mP(atl.jpg,None) , 3 , mP(720,480) , 2 ), 480 , 0 , 240 , 0
gP( mP(atl.jpg,None) , 480 , 0 ) -> sP( mP(720,480) , 240 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 480 , 239 ) -> sP( mP(720,480) , 240 , 239 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 719 , 0 ) -> sP( mP(720,480) , 479 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 719 , 239 ) -> sP( mP(720,480) , 479 , 239 , ('r', 'g', 'b') )
Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 4 , mP(720,480) , 6 ), 0 , 240 , 480 , 240
gP( mP(atl.jpg,None) , 0 , 240 ) -> sP( mP(720,480) , 480 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 0 , 479 ) -> sP( mP(720,480) , 480 , 479 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 239 , 240 ) -> sP( mP(720,480) , 719 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 239 , 479 ) -> sP( mP(720,480) , 719 , 479 , ('r', 'g', 'b') )
Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 5 , mP(720,480) , 1 ), 240 , 240 , 0 , 0
gP( mP(atl.jpg,None) , 240 , 240 ) -> sP( mP(720,480) , 0 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 240 , 479 ) -> sP( mP(720,480) , 0 , 239 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 479 , 240 ) -> sP( mP(720,480) , 239 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 479 , 479 ) -> sP( mP(720,480) , 239 , 239 , ('r', 'g', 'b') )
Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 6 , mP(720,480) , 5 ), 480 , 240 , 240 , 240
gP( mP(atl.jpg,None) , 480 , 240 ) -> sP( mP(720,480) , 240 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 480 , 479 ) -> sP( mP(720,480) , 240 , 479 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 719 , 240 ) -> sP( mP(720,480) , 479 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 719 , 479 ) -> sP( mP(720,480) , 479 , 479 , ('r', 'g', 'b') )
show( mP(720,480) , Scrambled Picture )

##from myro import *
from random import *
def getPixel(a,b,c):
    print "gP(",a,',',b,',',c,') ->',
    return ('r','g','b')

def getRGB(a):
##    print "getRGB(",a,')'
    return 'r','g','b'

def makeColor(a,b,c):
    return ('r','g','b')

def makePicture(a,b=None):
    print "makePicture(",a,',',b,'),',
    return ("mP("+str(a)+','+str(b)+')')

def show(a,b):
    print "show(",a,',',b,')'

def setPixel(a,b,c,d):
   print "sP(",a,',',b,',',c,',',d,')'

def moveCell(pic1,cell1,pic2,cell2):
    print "moveCell(",pic1,',',cell1,',',pic2,',',cell2,'),',
    x1 = 240*((cell1-1)%3)
    y1 = 240*((cell1-1)/3)
    x2 = 240*((cell2-1)%3)
    y2 = 240*((cell2-1)/3)
    print x1,',',y1,',',x2,',',y2
    for i in (0,239): ## only first and last iter range(240):
        for j in (0,239): ## only first and last iter range(240):
            pix1 = getPixel(pic1,x1+i,y1+j)
            r,g,b = getRGB(pix1)
            color = makeColor(r,g,b)
            setPixel(pic2,x2+i,y2+j,color)
        

def exchangeCell(pic1,cell1,pic2,cell2):
    print "exchangeCell(",pic1,',',cell1,',',pic2,',',cell2,')',
    x1 = 240*((cell1-1)%3)
    y1 = 240*((cell1-1)/3)
    x2 = 240*((cell2-1)%3)
    y2 = 240*((cell2-1)/3)
    print x1,',',y1,',',x2,',',y2
    for i in (0,239): ## only first and last iter range(240):
        for j in (0,239): ## only first and last iter range(240):
            pix1 = getPixel(pic1,x1+i,y1+j)
            r,g,b = getRGB(pix1)
            color = makeColor(r,g,b)
            setPixel(pic2,x2+i,y2+j,color)

pic = makePicture("atl.jpg")
show(pic,"Original Picture")
occupied = [False,False,False,False,False,False]
scrambledPic = makePicture(720,480)
for i in range(1,7):
    cell = input("Cell number (1-6) to exchange:")
    if cell == 0:
            break
    n = randint(1,6)
    while occupied[n-1] == True:  ## random cell which is unoccupied
        n = randint(1,6)
    moveCell(pic,i,scrambledPic,n)
    occupied[n-1] = True
show(scrambledPic,"Scrambled Picture")

Little more action by taking first and last iteration of loops to simulation.

>>> 
makePicture( atl.jpg , None ),
----------------------------------------
Original Picture
mP(atl.jpg,None)
----------------------------------------
makePicture( 720 , 480 ),
Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 1 , mP(720,480) , 3 ), 0 , 0 , 480 , 0
gP( mP(atl.jpg,None) , 0 , 0 ) -> sP( mP(720,480) , 480 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 0 , 239 ) -> sP( mP(720,480) , 480 , 239 , ('r', 'g', 'b') )
----------------------------------------
gP( mP(atl.jpg,None) , 239 , 0 ) -> sP( mP(720,480) , 719 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 239 , 239 ) -> sP( mP(720,480) , 719 , 239 , ('r', 'g', 'b') )
----------------------------------------
Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 2 , mP(720,480) , 5 ), 240 , 0 , 240 , 240
gP( mP(atl.jpg,None) , 240 , 0 ) -> sP( mP(720,480) , 240 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 240 , 239 ) -> sP( mP(720,480) , 240 , 479 , ('r', 'g', 'b') )
----------------------------------------
gP( mP(atl.jpg,None) , 479 , 0 ) -> sP( mP(720,480) , 479 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 479 , 239 ) -> sP( mP(720,480) , 479 , 479 , ('r', 'g', 'b') )
----------------------------------------
Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 3 , mP(720,480) , 1 ), 480 , 0 , 0 , 0
gP( mP(atl.jpg,None) , 480 , 0 ) -> sP( mP(720,480) , 0 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 480 , 239 ) -> sP( mP(720,480) , 0 , 239 , ('r', 'g', 'b') )
----------------------------------------
gP( mP(atl.jpg,None) , 719 , 0 ) -> sP( mP(720,480) , 239 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 719 , 239 ) -> sP( mP(720,480) , 239 , 239 , ('r', 'g', 'b') )
----------------------------------------
Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 4 , mP(720,480) , 6 ), 0 , 240 , 480 , 240
gP( mP(atl.jpg,None) , 0 , 240 ) -> sP( mP(720,480) , 480 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 0 , 479 ) -> sP( mP(720,480) , 480 , 479 , ('r', 'g', 'b') )
----------------------------------------
gP( mP(atl.jpg,None) , 239 , 240 ) -> sP( mP(720,480) , 719 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 239 , 479 ) -> sP( mP(720,480) , 719 , 479 , ('r', 'g', 'b') )
----------------------------------------
Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 5 , mP(720,480) , 4 ), 240 , 240 , 0 , 240
gP( mP(atl.jpg,None) , 240 , 240 ) -> sP( mP(720,480) , 0 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 240 , 479 ) -> sP( mP(720,480) , 0 , 479 , ('r', 'g', 'b') )
----------------------------------------
gP( mP(atl.jpg,None) , 479 , 240 ) -> sP( mP(720,480) , 239 , 240 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 479 , 479 ) -> sP( mP(720,480) , 239 , 479 , ('r', 'g', 'b') )
----------------------------------------
Cell number (1-6) to exchange:1
moveCell( mP(atl.jpg,None) , 6 , mP(720,480) , 2 ), 480 , 240 , 240 , 0
gP( mP(atl.jpg,None) , 480 , 240 ) -> sP( mP(720,480) , 240 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 480 , 479 ) -> sP( mP(720,480) , 240 , 239 , ('r', 'g', 'b') )
----------------------------------------
gP( mP(atl.jpg,None) , 719 , 240 ) -> sP( mP(720,480) , 479 , 0 , ('r', 'g', 'b') )
gP( mP(atl.jpg,None) , 719 , 479 ) -> sP( mP(720,480) , 479 , 239 , ('r', 'g', 'b') )
----------------------------------------
----------------------------------------
Scrambled Picture
mP(720,480)
----------------------------------------
>>>
##from myro import *
from random import *
def getPixel(a,b,c):
    print "gP(",a,',',b,',',c,') ->',
    return ('r','g','b')

def getRGB(a):
##    print "getRGB(",a,')'
    return 'r','g','b'

def makeColor(a,b,c):
    return (a,b,c)

def makePicture(a,b=None):
    print "makePicture(",a,',',b,'),'
    return ("mP("+str(a)+','+str(b)+')')

def show(a,b):
    print '-'*40
    print b
    print a
    print '-'*40

def setPixel(a,b,c,d):
   print "sP(",a,',',b,',',c,',',d,')'

def moveCell(pic1,cell1,pic2,cell2):
    print "moveCell(",pic1,',',cell1,',',pic2,',',cell2,'),',
    x1 = 240*((cell1-1)%3)
    y1 = 240*((cell1-1)/3)
    x2 = 240*((cell2-1)%3)
    y2 = 240*((cell2-1)/3)
    print x1,',',y1,',',x2,',',y2
    for i in (0,239): ## only first and last iter range(240):
        for j in (0,239): ## only first and last iter range(240):
            pix1 = getPixel(pic1,x1+i,y1+j)
            r,g,b = getRGB(pix1)
            color = makeColor(r,g,b)
            setPixel(pic2,x2+i,y2+j,color)
        print '-'*40
        

def exchangeCell(pic1,cell1,pic2,cell2):
    print "exchangeCell(",pic1,',',cell1,',',pic2,',',cell2,')',
    x1 = 240*((cell1-1)%3)
    y1 = 240*((cell1-1)/3)
    x2 = 240*((cell2-1)%3)
    y2 = 240*((cell2-1)/3)
    print x1,',',y1,',',x2,',',y2
    for i in (0,239): ## only first and last iter range(240):
        for j in (0,239): ## only first and last iter range(240):
            pix1 = getPixel(pic1,x1+i,y1+j)
            r,g,b = getRGB(pix1)
            color = makeColor(r,g,b)
            setPixel(pic2,x2+i,y2+j,color)
        print '-'*40

pic = makePicture("atl.jpg")
show(pic,"Original Picture")
occupied = [False,False,False,False,False,False]
scrambledPic = makePicture(720,480)
for i in range(1,7):
    cell = input("Cell number (1-6) to exchange:")
    if cell == 0:
            break
    n = randint(1,6)
    while occupied[n-1] == True:  ## random cell which is unoccupied
        n = randint(1,6)
    moveCell(pic,i,scrambledPic,n)
    occupied[n-1] = True
show(scrambledPic,"Scrambled Picture")

Edited 6 Years Ago by pyTony: Debug run simulation

This question has already been answered. Start a new discussion instead.