5. Loops 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus

Slides:



Advertisements
Similar presentations
How many sides? This is a basic counting game with action buttons and voiceover. The initial slide (coming up next) will run automatically and name the.
Advertisements

Polygons Only one of these is a polygon. Do you know? A polygon MUST be a closed figure.
Definitions and formulas for the shapes you love Perimeter and Area.
What is a Polygon? Dr. Beth McCulloch Vinson Athens State University PT3 Grant Funding, Summer 2000.
2-D Shapes What is a 2D Shape and how do we define it?
2 D shapes only have two dimensions, such as width and length Some are: Polygons and Some are: Not Polygons.
Simple Python Loops Sec 9-7 Web Design.
1 CS1110, 8 March 2009 Two topics: elementary graphics (for A5); loops Reading: Sec and chapter 7 on loops. The lectures on the ProgramLive CD can.
Class 2 Introduction to turtle graphics
Agent P, I have been hearing some rumours about a Python Turtle.
Chapter 1. Objectives To provide examples of computer science in the real world To provide an overview of common problem- solving strategies To introduce.
Polygons Polygons are many-sided closed figures, with sides that are line segments. Polygons are named according to the number of sides and angles they.
For loops in programming Assumes you have seen assignment statements and print statements.
CONTROL FLOW The order in which blocks are executed is called the “control flow” of the script So far all our scripts have just executed blocks in the.
Calculating the area of a leaning triangle. Calculating Area.
Getting started with the turtle Find the latest version of this document at
Week 3 DO NOW QUESTIONS. In this setup procedure the programmer intended to create one turtle of each color: red, green, and blue. What went wrong? to.
7. Lists 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
1. Starting 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Let’s Learn 3. Modules Saenthong School, January – February 2016
8. Functions 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Turtle Graphics Let’s see what we can draw on Python!
Turtle Graphics Lesson 2 1. There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has.
Chant and Write by Dr. Jean
SHAPES There are many shapes in our world. These are circles. Circles are never ending lines.
Geometry (Basic Shapes) Created by Ms. Creasy. Line A line goes on “forever” in both directions. It never stops. You know it is a line if it has an arrow.
4. If Statements 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
For loops. turtle drawings – common core state standards 1.1 Innovate: Demonstrate creative thinking, construct knowledge and develop innovative products.
Polygons Only one of these is a polygon. Do you know? A polygon MUST be a closed figure.
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Hackety Hack! Written by Krystal Salerno Presented by _______________.
5. Animation Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
5. Loops 1 Make a program do things over-and-over-and over again. Counting loops; Conditional loops. Games: guessing, ghost, hangman Computer.
Using the Python Turtle
Stage 3: Artist What do you remember from the last class?
Computer Programming.
Week 3 DO NOW QUESTIONS.
What is a Polygon?.
Keep coding Bekir Mugayitoglu.
Lesson 05: Iterations Class Chat: Attendance: Participation
11. Animation Let's Learn Python and Pygame
What is a Polygon?.
What is a Polygon? Dr. Beth McCulloch Vinson Athens State University
5. Loops Let's Learn Python and Pygame
Agent P, I have been hearing some rumours about a Python Turtle.
What are variables? Using input()
Let's Learn Python and Pygame
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
What is a Polygon? Dr. Beth McCulloch Vinson Athens State University
Lesson 05: Iterations Topic: Introduction to Programming, Zybook Ch 4, P4E Ch 5. Slides on website.
Let’s Learn 6. Nested Loops Saenthong School, January – February 2016
Module 2 Lesson 3 Over and Over Again
Let's Learn Python and Pygame
BSc in Digital Media, PSUIC
7. Functions Computer Programming BSc in Digital Media, PSUIC
IST256 : Applications Programming for Information Systems
7. Functions Let's Learn Python and Pygame
Chap. 3 Functions Start Python IDLE (Shell) and open a new file.
Looping Topic 4.
Section 3 Programming with Turtle Graphics
What are variables? Using input()
What is a Polygon? Dr. Beth McCulloch Vinson Athens State University
All About Shapes! Let’s Go!.
SHAPES By: Ms. Conquest.
Module 2 Lesson 3 Over and Over Again
What are variables? Using input()
Module 2 Lesson 3 Over and Over Again
What is a Polygon? Dr. Beth McCulloch Vinson Athens State University
2 Making Blocks.
This is a square. This is a square. How can you tell. How can you tell
Presentation transcript:

5. Loops 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus Make a program do things over-and-over-and over again. Counting loops; Conditional loops. Games: guessing, ghost, hangman.

1. Counting Loop 2 Loop1.py

Using the Counting Loop Variable 3 Loop2.py The [ … ] is called a list. More later

Using the Counting Loop Var. 4 Loop3.py

Counting without Numbers 5 A list can contain anything, not just numbers Coolest.py

Counting Loop Using a Range 6 Loop4.py Less typing, but it goes from 1 to 4

Eight Times Table 7 This range goes from 1 to 10 EightTimes.py

Range with a Step Amount 8 This range goes from 10 to 1 in a step of -1 BlastOff.py This program took 10 secs to run.

from turtle import Turtle t = Turtle() t.forward(100) t.right(90) t.forward(100) t.right(90) t.forward(100) t.right(90) t.forward(100) t.right(90) 2. Drawing a Turtle Square 9 This is Square.py from the Modules slides. The forward() and right() code is repeated four times. A loop will make this code smaller, and easier to change.

Square.py with a Loop 10

Square1.py with Variables 11 The variables make it easy to change the code. What if numSides == 3 and angle = 120?

Shape.py 12

 For a square, numSides == 4, angle == 90  For a triangle, numSides == 3, angle == 120  The math connection:  numSides * angle == 360  Test it. A 5-sided shape (pentagon) means:  5 * angle == 360  so angle = 360/5 Connect No. Sides and Angle 13

Revised Shape.py 14

 In ShapeInput.py  read in the numSides data using the turtle command numinput()  calculate the angle using the numSides data Make Shape Code Easier to Use 15

ShapeInput.py 16

17

A Square Spiral 18 SquareSpiral1.py

Square (90   91  ) + Color 19 SquareSpiral3.py

Square  Circle 20

Square Spiral Again 21 ColorSquareSpiral.py with different colors

Spiral with Adjustable Sides 22 ColorSpiral.py

Execution: 6  2 sides 23

Spiral Steps 24 Spiral Steps.py

Execution 25

 A conditional loop uses a test to decide when to stop looping  the same kind of test as in "if" 3. Conditional Loops 26

Eight Times Table Again 27 i < 11 is the test the while body is run over and over most while body's need to include an increment WhileLess.py

Eight Times Table Problem 28 WhileProb.py i never changes because there is no increment. This means i never reaches 11 and so the loop never ends. I typed ctrl-c

While that Likes "3" 29 While3.py

Using continue in a Loop 30 Continuer.py continue makes Python start the next loop straight away

Using break in a Loop 31 Breaker.py break makes Python leave the loop

4. A Number Guessing Game 32 GuessingGame.py

34

35 Uses two modules; a while loop; if tests

5. Ghost Game

ghostGame.py 37

6. Hangman 38 hangman.py