Let’s Learn 6. Nested Loops Saenthong School, January – February 2016

Slides:



Advertisements
Similar presentations
Introduction to Computing Science and Programming I
Advertisements

CIS 234: Control Structures: Selection Original by Dr. Ralph D. Westfall Modified by Dr V.
Loops – While, Do, For Repetition Statements Introduction to Arrays
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Nested Loops. Nesting Control Structures One if statement inside another one An if statement inside a loop A loop inside an if statement Control structures.
Fast food restaurants. What do they have… hamburger fried chicken chicken nugget sandwich hotdog French fries baked potato salad onion ring.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
5. Loops 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
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
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
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.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
Learning Objectives 1. Understand how the Small Basic Turtle operates. 2. Be able to draw geometric patterns using iteration.
4. If Statements 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
11. Skier Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
5. Animation Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
4. If Statements 1 Have your program make choices. Depending on a test have a program do different things Computer Programming BSc in Digital.
5. Loops 1 Make a program do things over-and-over-and over again. Counting loops; Conditional loops. Games: guessing, ghost, hangman Computer.
String and Lists Dr. José M. Reyes Álamo.
Let’s Learn 12. Packaging a Game Saengthong School, June – August 2016
Chapter 4 Repetition Statements (loops)
Let’s Learn 2. Installing Pygame
The switch Statement, and Introduction to Looping
11. Animation Let's Learn Python and Pygame
Branching Constructs Review
Limiting Reactant Sandwich 2 pcs bread 1 slice meat 1 slice cheese
Intro to CS Monday, August 29
2-D Lists Taken from notes by Dr. Neil Moore
9. Drawing Let's Learn Python and Pygame
Intro to CS Monday, August 24
Control structures Chapter 3.
Introduction to Multiples
5. Loops Let's Learn Python and Pygame
4. If Statements Let's Learn Python and Pygame
BBC Microbit.
What are variables? Using input()
Let's Learn Python and Pygame
Arrays, For loop While loop Do while loop
Patterns and Algebraic rules
13. Sprites Let's Learn Python and Pygame
Sensors and Logic Switches
8. Starting Pygame Let's Learn Python and Pygame
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
10. User Input Let's Learn Python and Pygame
6. Lists Let's Learn Python and Pygame
Count Controlled Loops (Nested)
Module 2 Lesson 3 Over and Over Again
Line Following Behavior
Let's Learn Python and Pygame
BSc in Digital Media, PSUIC
7. Functions Computer Programming BSc in Digital Media, PSUIC
Practice with loops! What is the output of each function below?
7. Functions Let's Learn Python and Pygame
String and Lists Dr. José M. Reyes Álamo.
Let’s Learn 7. Sprites Saengthong School, June – August 2016
Patterns and Algebraic rules
FOOD MATH.
What are variables? Using input()
Print the following triangle, using nested loops
Module 2 Lesson 3 Over and Over Again
What are variables? Using input()
Module 2 Lesson 3 Over and Over Again
2-D Lists Taken from notes by Dr. Neil Moore
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Let’s Learn 6. Nested Loops Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus E-mail: ad@fivedots.coe.psu.ac.th 6. Nested Loops Loops inside loops

1. Draw a Line of Stars StarsLine.py A line of stars is one star printed again and again.

Draw a Block of Stars StarsBlock.py A loop that runs inside another loop is called a nested loop A block of stars is one star line printed again and again.

Draw Blocks of Stars StarsBlocks.py Two nested loops: blocks  block  line Blocks of stars are one star block printed again and again.

2. Star Steps StarSteps.py The range is 1 to numBlocks Steps of stars is one star line printed again and again, but with line length changing

Star Steps Showing the Variable StarStepsVar.py Star Steps Showing the Variable

3. Mult. Table for 5's MultTable.py The range is 1 to 10

Multi. Tables for 5, 6, 7 MultTables.py The range is 5 to 8 Multiplication Tables are one table printed again and again.

4. Drawing Many Shapes ShapeInput.py draws 1 shape using 1 loop:

If this loop was nested inside a numShapes loop, then many shapes could be printed. ShapesInput.py

A Different Offset So that we can see each shape, the outer numShapes loop moves the turtle using goto() this puts the turtle in a new position, but the turtle is still facing East A different offset would be to rotate the turtle before drawing a shape.

ShapesInput.py with Rotation

5. Hot Dog Combinations (combos) You can make a hot dog in lots of ways: with/without a sausage (dog) with/without bread (the bun) with/without tomato sauce (ketchup) with/without mustard with/without onion Some of these combos are silly. What are all the possible combos?

All the Combos: I always go for combo 29. What about you? What does combo 1 mean? How would you eat combo 7?

HotDogCombos.py Four nested loops

HotDogCombos2.py Prints the same as before, but the loops and ifs use False and True instead of 0 and 1

HotDog Calories What is the combo with the smallest number of calories? Combo 29 has 340 calories, which is high. Combo 1 is the best for a diet. What does it mean?

HotDogCalories.py I've switched back to loops using 0 and 1. Why?