Python
What is Python?
Python:
What is Python?
Python:
- Python is a computer programming language. It is easy to learn, and can be used to write all sorts of computer programs.
- People use Python to build games, online tools, and websites.
- Python looks like a mixture of recognizable words and characters, so it can be easily read and understood by humans.
Learning to Code in Python
Learning Python Video 1
Python for Kids
Python Loops 1
Python Loops 2
Python Loops 3
Coding Python with Turtle
Beginners Guide
Learning Python Video 1
Python for Kids
Python Loops 1
Python Loops 2
Python Loops 3
Coding Python with Turtle
Beginners Guide
Run Python & Turtle in a Browser
Skulpt
This website has an interactive python interpreter; it runs in the browser.
Examples of Python Turtle Code
Code 1: Turtle Drawing Code Using Loops and Colors
Note: Paste this code into the Skulpt code window. Then press Run
import turtle
t = turtle.Turtle()
for c in ['red', 'green', 'yellow', 'blue']:
t.color(c)
t.forward(75)
t.left(90)
for j in range (8):
t.forward (10)
t.right (45)
# Loop 2
for i in range (3):
t.forward (100)
t.right (120)
Python Code Commands
Python Turtle Commands
Source: Python_Turtle_cheat_sheets.pdf
| Get Ready to Draw | |
| import turtle | Make all the turtle commands available to your program |
| turtle.mode(‘logo’) | Set the mode |
| turtle.speed(integer) | Set the animation speed of the turtle. 1 = slowest, 10 = fastest. ) turns off animation completely |
| turtle.shape(‘turtle’) | Set the shape. You can also choose from: arrow, square, circle, triangle and classic |
| Move | |
| x, y = turtle.pos() | Go to position x, y |
| turtle.forward(distance) | Go forwards by amount distance |
| turtle.backward( | distance)Go backwards by amount |
| turtle.right( | angle)Turn right by |
| turtle.left( | angle)Turn left by |
| turtle.home() | Go home (0, 0) and face north |
| turtle.goto( | x, y)Go to position |
| turtle.setheading( | degrees)Point in compass direction |
| turtle.resizemode(‘auto’) | Use this command at the start of your program to change the size of the turtle when the pen size changes. Useful for stamping! |
| turtle.circle(radius) | Draw a circle with the given radius (a number). radius can be negative. |
| turtle.circle(radius, angle) | Draw a circle with the given radius (a number). radius can be negative. |
| Movement | |
| turtle.forward(distance) | Go forwards by amount distance |
| turtle.backward(distance) | Go backwards by amount distance |
| turtle.right( | angle)Turn right by |
| turtle.left( | angle)Turn left by |
| turtle.home() | Go home (0, 0) and face north |
| turtle.goto( | x, y)Sets the variables |
| turtle.setheading( | degrees)Point in compass direction |
| Paint Commands | |
| turtle.begin_fill() | Use this command before you start drawing the shape you want to be filled |
| turtle.end_fill() | Use this command when you have finished drawing the shape to be filled. |
| turtle.pendown() | Put the pen down to draw |
| turtle.penup() | ‘Lift’ the pen from the screen |
| turtle.pensize(integer) | Set the size of the pen to the given integer. |
| turtle.pencolor(string) | Set the pen color to the string given. Note the American spelling. |
| turtle.fillcolor(string) | Set the fill color to the string given. See list of colors below. |
| turtle.color(string) | Set both the fill color and pen color to given string (color). |
| turtle.color(string1, string2) | Set the pen and fill color at the same time. String1 should be the name of the pen color, and string2 is the fill color. |
| turtle.stamp() | Stamp the current turtle shape onto the screen. |
| turtle.clearstamps() | Clear all of the stamps on the screen. |
| stampID = turtle.stamp() | Stamps the turtle onto the screen, and sets the variable stampID to an integer, unique to each stamp. |
| turtle.clearstamp(stampID) | Clear the stamp with the given stampID number. |
Python Color Table
| Color List | AliceBlue | |
| AntiqueWhite | AntiqueWhite1 | AntiqueWhite2 |
| AntiqueWhite3 | AntiqueWhite4 | aquamarine |
| aquamarine1 | aquamarine2 | aquamarine3 |
| aquamarine4 | azure | azure1 |
| azure2 | azure3 | azure4 |
| beige | bisque | bisque1 |
| bisque2 | bisque3 | bisque4 |
| black | blanchedalmond | BlanchedAlmond |
| blue | blue1 | blue2 |
| blue3 | blue4 | BlueViolet |
| brown | brown1 | brown2 |
| brown3 | brown4 | burlywood |
| burlywood1 | burlywood2 | burlywood3 |
| burlywood4 | CadetBlue | CadetBlue1 |
| CadetBlue2 | CadetBlue3 | CadetBlue4 |
| chartreuse | chartreuse1 | chartreuse2 |
| chartreuse3 | chartreuse4 | chocolate |
| chocolate1 | chocolate2 | chocolate3 |
| chocolate4 | coral | coral1 |
| coral2 | coral3 | coral4 |
| CornflowerBlue | cornsilk | cornsilk1 |
| cornsilk2 | cornsilk3 | cornsilk4 |
| cyan | cyan1 | cyan2 |
| cyan3 | cyan4 | DarkBlue |
| DarkCyan | DarkGoldenrod | DarkGoldenrod1 |
| DarkGoldenrod2 | DarkGoldenrod3 | DarkGoldenrod4 |
| DarkGray | DarkGreen | DarkGrey |
| DarkKhaki | DarkMagenta | DarkOliveGreen |
| DarkOliveGreen1 | DarkOliveGreen2 | DarkOliveGreen3 |
| DarkOliveGreen4 | DarkOrange | DarkOrange1 |
| DarkOrange2 | DarkOrange3 | DarkOrange4 |
| DarkOrchid | DarkOrchid1 | DarkOrchid2 |
| DarkOrchid3 | DarkOrchid4 | DarkRed |
| DarkSalmon | DarkSeaGreen | DarkSeaGreen1 |
| DarkSeaGreen2 | DarkSeaGreen3 | DarkSeaGreen4 |
| DarkSlateBlue | DarkSlateGray | DarkSlateGray1 |
| DarkSlateGray2 | DarkSlateGray3 | DarkSlateGray4 |
| DarkSlateGrey | DarkTurquoise | DarkViolet |
| DeepPink | DeepPink1 | DeepPink2 |
| DeepPink3 | DeepPink4 | DeepSkyBlue |
| DeepSkyBlue1 | DeepSkyBlue2 | DeepSkyBlue3 |
| DeepSkyBlue4 | DimGray | DimGrey |
| DodgerBlue | DodgerBlue1 | DodgerBlue2 |
| DodgerBlue3 | DodgerBlue4 | firebrick |
| firebrick1 | firebrick2 | firebrick3 |
| firebrick4 | FloralWhite | ForestGreen |
| gainsboro | GhostWhite | gold |
| gold1 | gold2 | gold3 |
| gold4 | goldenrod | goldenrod1 |
| goldenrod2 | goldenrod3 | goldenrod4 |
| green | green1 | green2 |
| green3 | green4 | GreenYellow |
| grey | LightBlue2 | LightBlue3 |
| LightBlue4 | LightCoral | LightCyan |
| LightCyan1 | LightCyan2 | LightCyan3 |
| LightCyan4 | LightGoldenrod | greyX |
| honeydew | honeydew1 | honeydew2 |
| honeydew3 | honeydew4 | HotPink |
| HotPink1 | HotPink2 | HotPink3 |
| HotPink4 | IndianRed | IndianRed1 |
| IndianRed2 | IndianRed3 | IndianRed4 |
| ivory | ivory1 | ivory2 |
| ivory3 | ivory4 | khaki |
| khaki1 | khaki2 | khaki3 |
| khaki4 | lavender | LavenderBlush |
| LavenderBlush1 | LavenderBlush2 | LavenderBlush3 |
| LavenderBlush4 | LawnGreen | LemonChiffon |
| LemonChiffon1 | LemonChiffon2 | LemonChiffon3 |
| LemonChiffon4 | LightBlue | LightBlue1 |
| LightGoldenrod1 | LightGoldenrod2 | LightGoldenrod3 |
| LightGoldenrod4 | LightGreen | LightGrey |
| LightPink | LightPink1 | LightPink2 |
| LightPink3 | LightPink4 | LightSalmon |
| LightSalmon1 | LightSalmon2 | LightSalmon3 |
| LightSalmon4 | LightSeaGreen | LightSkyBlue |
| LightSkyBlue1 | LightSkyBlue2 | LightSkyBlue3 |
| LightSkyBlue4 | LightSlateBlue | LightSlateGrey |
| LightSteelBlue | LightSteelBlue1 | LightSteelBlue2 |
| LightSteelBlue3 | LightSteelBlue4 | LightYellow |
| LightYellow1 | LightYellow2 | LightYellow3 |
| LightYellow4 | LimeGreen | linen |
| magenta | magenta1 | magenta2magenta3 |
| magenta4 | maroon | maroon1 |
| maroon2 | maroon3 | maroon4 |
| MediumAquamarine | MediumBlue | MediumOrchid |
| MediumOrchid1 | MediumOrchid2 | MediumOrchid3 |
| MediumOrchid4 | MediumPurple | MediumPurple1 |
| MediumPurple2 | MediumPurple3 | MediumPurple4 |
| MediumSeaGreen | MediumSlateBlue | MediumSpringGreen |
| MediumTurquoise | MediumVioletRed | MidnightBlue |
| MintCream | MistyRose | MistyRose1 |
| MistyRose2 | MistyRose3 | MistyRose4 |
| moccasin | NavajoWhite | NavajoWhite1 |
| NavajoWhite2 | NavajoWhite3 | NavajoWhite4 |
| NavyBlue | OldLace | OliveDrab |
| OliveDrab1 | OliveDrab2 | OliveDrab3 |
| OliveDrab4 | orange | orange1 |
| orange2 | orange3 | orange4 |
| OrangeRed | OrangeRed1 | OrangeRed2 |
| OrangeRed3 | OrangeRed4 | orchid |
| orchid1 | orchid2 | orchid3 |
| orchid4 | PaleGoldenrod | PaleGreen |
| PaleGreen1 | PaleGreen2 | PaleGreen3 |
| PaleGreen4 | PaleTurquoise | PaleTurquoise1 |
| PaleTurquoise2 | PaleTurquoise3 | PaleTurquoise4 |
| PaleVioletRed | PaleVioletRed1 | PaleVioletRed2 |
| PaleVioletRed3 | PaleVioletRed4 | PapayaWhip |
| PeachPuff | PeachPuff1 | PeachPuff2 |
| PeachPuff3 | PeachPuff4 | peru |
| pink | pink1 | pink2 |
| pink3 | pink4 | plum |
| plum1 | plum2 | plum3 |
| plum4 | PowderBlue | purple |
| purple1 | purple2 | purple3 |
| purple4 | red | red1 |
| red2 | red3 | red4 |
| RosyBrown | RosyBrown1 | RosyBrown2 |
| RosyBrown3 | RosyBrown4 | RoyalBlue |
| RoyalBlue1 | RoyalBlue2 | RoyalBlue3 |
| RoyalBlue4 | SaddleBrown | salmon |
| salmon1 | salmon2 | salmon3 |
| salmon4 | SandyBrown | SeaGreen |
| SeaGreen1 | SeaGreen2 | SeaGreen3 |
| SeaGreen4 | seashell | seashell1 |
| seashell2 | seashell3 | seashell4 |
| sienna | sienna1 | sienna2 |
| sienna3 | sienna4 | SkyBlue |
| SkyBlue1 | SkyBlue2 | SkyBlue3 |
| SkyBlue4 | SlateBlue | SlateBlue1 |
| SlateBlue2 | SlateBlue3 | SlateBlue4 |
| SlateGrey | snow | snow1 |
| snow2 | snow3 | snow3 |
| snow4 | SpringGreen | SpringGreen1 |
| SpringGreen2 | SpringGreen3 | SpringGreen4 |
| SteelBlue | SteelBlue1 | SteelBlue2 |
| SteelBlue3 | SteelBlue4 | tan |
| tan1 | tan2 | tan3 |
| tan4 | thistle | thistle1 |
| thistle2 | thistle3 | thistle4 |
| tomato | tomato1 | tomato2 |
| tomato3 | tomato4 | turquoise |
| turquoise1 | turquoise2 | turquoise3 |
| turquoise4 | violet | VioletRed |
| VioletRed1 | VioletRed2 | VioletRed3 |
| VioletRed4 | wheat | wheat1 |
| wheat2 | wheat3 | wheat4 |
| white | WhiteSmoke | yellow |
| yellow1 | yellow2 | yellow3 |
| yellow4 | YellowGreen |
