GoConqr has a new look! Let us know what you think.

Notes

Python Chapter 3 Test Study Guide

Suhani Arora English 1 page

Content of the notes (1)

Page 1

Python Chp 3 Test Study Guide: Turtle

3.1 Notes: Our First Turtle Program

import turtle: Tells Python to load module named turtle.

wn = turtle.Screen(): creates a playground for turtles (wn is the variable that we assign screen to)

alex = turtle.Turtle: creates a turtle and assigns turtle to alex

All the lines written in bold above are how you should start each turtle code. They help set the code up.

That module brings us two new types that we can use: the Turtle type, and the Screen type.

The dot notation turtle.Turtle means “The Turtle type that is defined within the turtle module.”

Every window has a canvas. This is area inside of a window on which we can draw.

wn.mainloop(): this tells the code to wait for the user to close the window. The program will terminate when the user closes the window.

Each object has attributes, or properties such as color. To change alex's color, you say: alex.color("red"). This makes the drawing red too.

Methods and commands: To move forward: alex.forward(pixels) To move backward: alex.backward(pixels) To turn left: alex.left(degrees) and so on and so forth.

Other Commands:

alex.pensize changes pen width

alex.pencolor changes pen color

wn.bgcolor changes bg color

wn.title changes wn title

3.2 Notes: Instances - a herd of turtles

We can have many turtles. Each of them is called an instance.

3.3 Notes - The For Loop

The For Loop is a basic building block of all programs is to be able to repeat some code, over and over again.

This is the format of a for loop:

1 for i in ["Jack", "Joe", "Jill", "Jeff"]:

2 print("Hola")

In this case, i is a loop variable and line 2 is the loop body. The indentation determines exactly what statements are “in the body of the loop”.

On each iteration or pass of the loop, first a check is done to see if there are still more items to be processed. If there are none left (this is called the terminating condition of the loop), the loop has finished. Program execution continues at the next statement after the loop body.

If there are items still to be processed, the loop variable is updated to refer to the next item in the list. This means, in this case, that the loop body is executed here 7 times, and each time i will refer to a different friend.

At the end of each execution of the body of the loop, Python returns to the for statement, to see if there are more items to be handled, and to assign the next one to i.

3.4 Notes: Flow of Execution of the for loop

As a program executes, the interpreter always keeps track of which statement is about to be executed. This is known as the control flow, of the flow of execution of the program.

Information

Description
Note on Python Chapter 3 Test Study Guide, created by Suhani Arora on 02/03/2018.
Created by
Suhani Arora
Views
2
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?