i am trying to make a checkerboard that centerss automaticly no matter what the sideLength is. also i am tryiing to put the checker in the squares...im only a beginner!!!! have mercy

heres what i have

def drawCheckerBoard(myTurtle,sideLength):
    myTurtle.speed(0)
    for i in range (8):
        
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
    
    
    for i in range (1):
        myTurtle.right(90)
        myTurtle.forward(sideLength*2)
        myTurtle.right(90)
    for i in range(8):
        
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
    for i in range(1):
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)


    for i in range (8):
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)

    for i in range (1):
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
    for i in range(8):
        
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)

    for i in range(1):
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
    
   
    for i in range (8):
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
    for i in range (1):
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
    for i in range(8):
        
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
    for i in range(1):
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
    
   
    for i in range (8):
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
    for i in range (1):
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
    for i in range(8):
        
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)

ah you must use scratch

Read the comments ...

# draw a checker board with Python module turtle

import turtle as myTurtle

def drawCheckerBoard(myTurtle, sideLength):

    myTurtle.speed('fastest')

    # turtle by default starts at (x=0, y=0) center of a (450x550) window
    # to pick another center lift the pen up then move
    # to the left -x units and up y units
    # now drop the pen down to start drawing
    myTurtle.up()
    # sideLength * 4 should be okay for centering
    myTurtle.goto(-4 * sideLength, 4 * sideLength)
    myTurtle.down()

    for i in range (8):
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)

    for i in range (1):
        myTurtle.right(90)
        myTurtle.forward(sideLength*2)
        myTurtle.right(90)

    for i in range(8):
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)

    for i in range(1):
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)

    for i in range (8):
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)

    for i in range (1):
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)

    for i in range(8):
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)

    for i in range(1):
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)

    for i in range (8):
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)

    for i in range (1):
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)

    for i in range(8):
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)

    for i in range(1):
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)

    for i in range (8):
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)
        myTurtle.left(90)
        myTurtle.forward(sideLength)

    for i in range (1):
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)

    for i in range(8):
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)
        myTurtle.right(90)
        myTurtle.forward(sideLength)


myTurtle.title('centered checker board')
# test it ...
sideLength = 40
drawCheckerBoard(myTurtle,sideLength)

# keep showing until window corner x is clicked
myTurtle.done()
from turtle import*
title('sah')
fd (160)
for i in range(4):
    lt(90)
    fd (20)
    lt(90)
    fd(160)

    rt(90)
    fd(20)
    rt(90)
    fd(160)
rt(90)
fd(160)
for i in range(4):
    rt(90)
    fd(20)
    rt(90)
    fd(160)

    lt(90)
    fd (20)
    lt(90)
    fd(160)

mainloop()

(If you dont want to write 150 lines to do this.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.