DrawRectangleBrick() missing 1 required positional argument: 'y'

Question:

I am trying to create a brick wall using turtle for my python coding class and I cannot figure out why I am receiving the error
"DrawRectangleBrick() missing 1 required positional argument: ‘y’"
here is where the issue is:

def DrawRectangleBrick(x,y):
    global SQUARE_SIZE

    for i in range(4):
        if i% 2 == 0:
            tr.forward(SQUARE_SIZE * 2)
            tr.left(90)
        else:
            tr.forward(SQUARE_SIZE)
            tr.left(90)

here is the beginning of my code:

import turtle

SQUARE_SIZE = 40
tr = turtle.Turtle()


def InitTurtle():
    scr = turtle.Screen()
    tr.color("black")
    tr.width("1")
    tr.speed(20)
    tr.penup()
    tr.goto(-300,-300)
    tr.pendown()

def DrawSquareBrick(x,y):
    global SQUARE_SIZE

    for i in range(4):
        tr.forward(SQUARE_SIZE)
        tr.left(90)

def DrawRectangleBrick(x,y):
    global SQUARE_SIZE

    for i in range(4):
        if i% 2 == 0:
            tr.forward(SQUARE_SIZE * 2)
            tr.left(90)
        else:
            tr.forward(SQUARE_SIZE)
            tr.left(90)

Edit:

here is the full code:


import turtle

SQUARE_SIZE = 40
tr = turtle.Turtle()


def InitTurtle():
    scr = turtle.Screen()
    tr.color("black")
    tr.width("1")
    tr.speed(20)
    tr.penup()
    tr.goto(-300,-300)
    tr.pendown()

def DrawSquareBrick(x,y):
    global SQUARE_SIZE

    for i in range(4):
        tr.forward(SQUARE_SIZE)
        tr.left(90)

def DrawRectangleBrick(x,y):
    global SQUARE_SIZE

    for i in range(4):
        if i% 2 == 0:
            tr.forward(SQUARE_SIZE * 2)
            tr.left(90)
        else:
            tr.forward(SQUARE_SIZE)
            tr.left(90)

def DrawRowOfRectangleBricks(yPos):
   global SQUARE_SIZE
   xPos = -300
   tr.pendown()
   for i in range(8):
       DrawRectangleBrick(xPos)
       xPos += SQUARE_SIZE
   tr.penup()

def DrawRowOfBricksStartingWithSquare(yPos):
    global SQUARE_SIZE
    xPos = -300
    tr.pendown()
    for i in range:
        DrawSquareBrick(xPos)
        xPos += SQUARE_SIZE
        DrawRectangleBrick(xPos)
        XPos += SQUARE_SIZE
        DrawRectangleBrick(xPos)
        XPos += SQUARE_SIZE
        DrawRectangleBrick(xPos)
        XPos += SQUARE_SIZE
        DrawRectangleBrick(xPos)
        XPos += SQUARE_SIZE
        DrawRectangleBrick(xPos)
        XPos += SQUARE_SIZE
        DrawRectangleBrick(xPos)
        XPos += SQUARE_SIZE
        DrawRectangleBrick(xPos)
        XPos += SQUARE_SIZE
        DrawSquareBrick(xPos)
    tr.penup()

def main():
    global SQUARE_SIZE

    InitTurtle()
    yPos = -300

    for i in range(8):
        DrawRowOfRectangleBricks(yPos)
        yPos += SQUARE_SIZE
        DrawRowOfBricksStartingWithSquare(yPos)
        yPos += SQUARE_SIZE

main()
turtle.done()

Asked By: Skugggs

||

Answers:

Since your DrawRectangleBrick takes to parameters x and y. You need to call the function with 2 parameters as well.

So, change all your

DrawRectangleBrick(xPos)

to

DrawRectangleBrick(xPos, yPos)
Answered By: Rahul K P
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.