Last active
July 21, 2021 04:38
-
-
Save shinysu/f383f1c0880d5d9eeee2e906188dfbaf to your computer and use it in GitHub Desktop.
Day 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
draw a line using turtle | |
''' | |
import turtle | |
t = turtle.Turtle() | |
t.forward(100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
draw a square | |
''' | |
import turtle | |
t = turtle.Turtle() | |
t.forward(100) | |
t.left(90) | |
t.forward(100) | |
t.left(90) | |
t.forward(100) | |
t.left(90) | |
t.forward(100) | |
t.left(90) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
draw a square using loop | |
The statements within the for loop executes 4 times for i values, 0, 1, 2,3 | |
key concept - using loops for repeated statements | |
''' | |
import turtle | |
t = turtle.Turtle() | |
for i in range(4): | |
t.forward(100) | |
t.left(90) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
draw a square - replace all magic numbers with variables | |
key concept - using variables for storing values | |
''' | |
import turtle | |
t = turtle.Turtle() | |
sides = 4 | |
length = 100 | |
angle = 360 / sides | |
for i in range(sides): | |
t.forward(length) | |
t.left(angle) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
draw a polygon - using a function | |
key concept - using functions for block of code that performs an action | |
syntax: def function_name(): | |
''' | |
import turtle | |
def draw_shape(t, sides, length): | |
angle = 360 / sides | |
for i in range(sides): | |
t.forward(length) | |
t.left(angle) | |
t = turtle.Turtle() | |
draw_shape(t, 4, 100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
draw a pattern | |
''' | |
import turtle | |
def draw_shape(t, sides, length): | |
angle = 360 / sides | |
for i in range(sides): | |
t.forward(length) | |
t.left(angle) | |
t=turtle.Turtle() | |
t.color("red") | |
for i in range(20): | |
draw_shape(t, 4, 100) | |
t.left(18) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank You It Was Usefully 🙂