Python assignment help!


#1

I am having various issues with a Python assignment for class. The code I have is below but I am having trouble between the two comment lines


The error was: 19
Sequence index out of range.
The index you're using goes beyond the size of that data (too low or high). For instance, maybe you tried to access OurArray[10] and OurArray only has 5 elements in it.
Please check line 90

The error value is: 'int' object is unsubscriptable
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer.
Please check line 93


import random,time 

def INT(N):
    return int(round(N))
     
def addCircle(Canvas,Xc,Yc,R,NewColor=black): 
    Diameter = INT(2*R+1)
    addOval(Canvas,INT(Xc-R),INT(Yc-R),Diameter,Diameter,NewColor) 
    return 
     
def addCircleFilled(Canvas,Xc,Yc,R,NewColor=black): 
    Diameter = INT(2*R+1)
    addOvalFilled(Canvas,INT(Xc-R),INT(Yc-R),Diameter,Diameter,NewColor) 
    return 
    
def Circles(Canvas,Xc,Yc,R,FillColor=white,EdgeColor=black):
    addCircleFilled(Canvas,Xc,Yc,R,FillColor)
    addCircle(Canvas,Xc,Yc,R,EdgeColor)
    return
     
def addEllipse(Canvas,Xc,Yc,Xr,Yr,NewColor=black): 
    addOval(Canvas,INT(Xc-Xr),INT(Yc-Yr),INT(2*Xr+1),INT(2*Yr+1),NewColor) 
    return 
     
def addEllipseFilled(Canvas,Xc,Yc,Xr,Yr,NewColor=black): 
    addOvalFilled(Canvas,INT(Xc-Xr),INT(Yc-Yr),INT(2*Xr+1),INT(2*Yr+1),NewColor) 
    return 
     
def Ellipses(Canvas,Xc,Yc,Xr,Yr,FillColor=white,EdgeColor=black):
    addEllipseFilled(Canvas,Xc,Yc,Xr,Yr,FillColor)
    addEllipse(Canvas,Xc,Yc,Xr,Yr,EdgeColor)
    return
    
def Line (Canvas,X1,Y1,X2,Y2,NewColor=black):
    addLine(Canvas,INT(X1),INT(Y1),INT(X2),INT(Y2),NewColor)
    return
    
def FishLeft (Canvas,Xc,Yc,NewColor,Scale=1.0):

    def F(N):
        return N*Scale 
        
    Ellipses(Canvas,Xc+F(14),Yc,F(3),F(14),white, black)  # Tail 
    Ellipses(Canvas,Xc,Yc,F(17),F(9),NewColor,black)      # Body 
    Circles(Canvas,Xc-F(10),Yc-F(2),F(3),white, black)    # Eye 
    Line(Canvas,Xc-F(15),Yc+F(4),Xc-F(7),Yc+F(4),white)   # Mouth 
    Line(Canvas,Xc-F(5),Yc+F(6),Xc-F(5),Yc-F(6),white)    # Gill
    return 
     
def FishRight (Canvas,Xc,Yc,NewColor,Scale=1.0): 

    def F(N):
        return N*Scale 
        
    Ellipses(Canvas,Xc-F(14),Yc,F(3),F(14),white, black)  # Tail 
    Ellipses(Canvas,Xc,Yc,F(17),F(9),NewColor, black)     # Body 
    Circles(Canvas,Xc+F(10),Yc-F(2),F(3),white, black)    # Eye 
    Line(Canvas,Xc+F(15),Yc+F(4),Xc+F(7),Yc+F(4),white)   # Mouth 
    Line(Canvas,Xc+F(5),Yc+F(6),Xc+F(5),Yc-F(6),white)    # Gill
    return 

#HELP     
def FishTank(Canvas, TotalFish=20):
    scale = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0]
    paint = [black,blue, green, cyan, red, magenta, yellow]
    X=[]
    for f in range(TotalFish):
      X = X + [getWidth(Canvas)/2 + random.randint(-25,26)]
    Y=[]
    for f in range(TotalFish):
      Y = Y + [getHeight(Canvas)/2 + random.randint(-25,26)]
    Xdirection=[]
    for f in range(TotalFish):
      Xdirection= Xdirection + [random.randint(-1,2)]
    Ydirection=[]
    for f in range(TotalFish):
      Ydirection= Ydirection + [random.randint(-1,2)]
    Colors=[]
    for f in range(TotalFish):
      Colors= Colors + [random.choice(paint)]
    Scale=[]
    for f in range(TotalFish):
      Scale= Scale + [random.choice(scale)]
    while (True):
      B = makeColor(0,0,128)
      setAllPixelsToAColor(Canvas,B)
      addText(Canvas,10,10,"name", white)
      for X in range(TotalFish):
        if (Xdirection[f] == -1):
          FishLeft(Canvas,X[f],Y[f],Colors[f],Scale[f])
        else:
          FishRight(Canvas,X[f],Y[f],Colors[f],Scale[f])
        X[f] = X[f] + Xdirection[f]
        Y[f] = Y[f] + Ydirection[f]
        if (X[f] > getWidth(Canvas)- 34): Xdirection[f]= -abs(Xdirection[f])
        elif (X[f] <= 0):Xdirection[f]= abs(Xdirection[f])
        if (Y[f] > getHeight(Canvas)- 28): Ydirection[f]= -abs(Ydirection[f])
        elif (Y[f] <= 0):Ydirection[f]= abs(Ydirection[f])
        if (random.randrange(0,10) == 0):
          Xdirection[f] = random.randrange(-1,2)
        if (random.randrange(0,20) == 0):
          Ydirection[f] = random.randrange(-1,2)
      repaint(Canvas)
      time.sleep(0.05)
    return
#HELP
 
def Run(): 
    TotalFish = requestIntegerInRange("Enter Number of Fish", 1, 1000)
    FishTank(makeEmptyPicture(640,480), TotalFish) 
    return


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.