7.4 Python - Turtle
STARTERS / ENDERSRESOURCES:
Extension: |
TASKS:This term we're going to be learning a computer programming language called Python. The person who created Python named it after his favourite TV show: Monty Python’s Flying Circus. Python is used by loads of programmers for many different things. Python is a powerful and clever language, used at YouTube, NASA, CERN and others.
STEP 1: HELLO, WORLD! Open the python_turtle_1 PDF from the resources section. Open IDLE, the editor that comes with Python. All our code will be written in this editor. When you open it,you will see an Output window, where errors and results will appear. click file new window to open the script mode.Follow the tutorial 1. STEP 2: HELLO, TURTLE! Next, we're going to have some fun with turtles. A turtle is a tiny robot that draws on your screen, we can tell it to move around using Python commands. STEP 3: DRAWING SHAPES! Lets make a square by telling the turtle how to move around. We will look at storing the turtles movement in variables that can be used again and again STEP 4: REPEATING YOURSELF (WITH A FOR LOOP) That last program was the same commands over and over again . Instead of writing them down, let's ask the computer to repeat them for us. You should have encountered iteration in Scratch before using the forever and repeat/repeat until blocks. In Python for loops are used when you have a piece of code which you want to repeat n number of times. In this case we want to repeat the code (that is indented) 4 times (because a square has 4 sides). STEP 5: TURN, TURN, TURN Instead of us working out the angle, why don't we let the computer do it for us. Python can let you do some operations on numbers, like addition, subtraction,multiplication and division. STEP 6: SOLID SHAPE We can ask the turtle to fill in shapes with a colour, by using begin fill and end fill commands STEP 7: PEN GOES UP, PEN GOES DOWN If you want to move the turtle without leaving a trail behind it, you can use pen up and pen down to turn drawing on and off. STEP 8: GO WILD! You can go forward() , backward(),left(),right() ,you can loop using for count in range (4), change colours, change speed and even fill in shapes! What shapes can you draw? |