Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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()

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading