Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Draw an Olympic Symbol in Python using Turtle
Next article icon

Prerequisite:Turtle Programming Basics

Turtle is an inbuilt module in Python. It provides drawing using a screen (cardboard) and turtle (pen). To draw something on the screen, we need to move the turtle (pen). To move turtle, there are some functions i.e forward(), backward(), etc.

For drawing Chess Board following steps are used :

  • Import turtle and making an object.
  • Set screen size and turtle position.
  • Define a method to draw a square
  • Call the method 8 times under another loop for 8 times with alternative color.
  • Hide the turtle object.

Below is the implementation :

python3
# import turtle packageimportturtle# create screen objectsc=turtle.Screen()# create turtle objectpen=turtle.Turtle()# method to draw squaredefdraw():foriinrange(4):pen.forward(30)pen.left(90)pen.forward(30)# Driver Codeif__name__=="__main__":# set screensc.setup(600,600)# set turtle object speedpen.speed(100)# loops for boardforiinrange(8):# not ready to drawpen.up()# set position for every rowpen.setpos(0,30*i)# ready to drawpen.down()# rowforjinrange(8):# conditions for alternative colorif(i+j)%2==0:col='black'else:col='white'# fill with given colorpen.fillcolor(col)# start filling with colourpen.begin_fill()# call methoddraw()# stop fillingpen.end_fill()# hide the turtlepen.hideturtle()# This code is contributed by Deepanshu Rustagi.

Output :


Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp