Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …

Slides:



Advertisements
Similar presentations
Introduction to Computing Science and Programming I
Advertisements

08 Deterministic iteration1May Deterministic iteration CE : Fundamental Programming Techniques.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Computer Science 1620 Loops.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
Advanced Decisions and Loops Chapter Some Simple Schoolroom Statistics.
Loop Exercise 1 Suppose that you want to take out a loan for $10,000, with 18% APR, and you're willing to make payments of $1,200/month. How long will.
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.
More While Loop Examples CS303E: Elements of Computers and Programming.
Nested LOOPS.
27/05/ Iteration Loops Nested Loops & The Step Parameter.
Python Repetition. We use repetition to prevent typing the same code out many times and to make our code more efficient. FOR is used when you know how.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Count Controlled Loops Look at the little children … Why is the sun’s face features orange …
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 5 Repetition.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: The while Statement cin within a while Loop The for.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Chapter 5 Repetition. 2 Objectives You should be able to describe: The while Statement cin within a while Loop The for Statement The do Statement Common.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 6, Lecture 1 (Monday)
Chapter 6: Looping. Objectives Learn about the loop structure Create while loops Use shortcut arithmetic operators Create for loops Create do…while loops.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Nested For Loops. First, the rules to these loops do not change. We are sticking one loop inside another. while(condition) { // loop body } do { // loop.
For loop. Exercise 1 Write a program to have the user input three (3) numbers: (f)rom, (t)o, and (i)ncrement. Count from f to t in increments of i, inclusive.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
Arrays. Arrays are objects that help us organize large amounts of information.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
CSC 211 Java I for loops and arrays.
Repetition Structures
Python Loops and Iteration
Chapter 5: Control Structure
While Loops in Python.
Topics Introduction to Repetition Structures
Lecture 07 More Repetition Richard Gesick.
Lecture 4B More Repetition Richard Gesick
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Repetition and Loop Statements
Control Structure Senior Lecturer
Python I/O.
Introduction to pseudocode
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Count Controlled Loops
Count Controlled Loops (Nested)
Intro to Nested Looping
Repetition Structures
Writing Functions( ) (Part 4)
Intro to Nested Looping
Python programming exercise
Let’s all Repeat Together
Using the Target Variable Inside the Loop
Objectives You should be able to describe: The while Statement
Python Basics with Jupyter Notebook
Intro to Nested Looping
Print the following triangle, using nested loops
The while Looping Structure
REPETITION Why Repetition?
Tuple.
Presentation transcript:

Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …

Practice – Divisibility  Write a program that asks the user for an integer  Then print out all numbers that are divisible by that number from 1 to 1,000

Practice – Divisibility (extension)  Extend your divisibility program to check for all integers from 1 to 10,000 that are divisible by two different integers simultaneously  Print out 10 numbers per line

Practice – Divisibility (extension)

Warm Up Exercise – Prime Numbers  Write a program that asks the user to enter an integers  Check to see if the number is prime and if not, print out the number that it is divisible by

Warm Up Exercise – Black Friday  Write a program that continually asks the user for a price value  When the user enters the word “end” you should end the program and add the total price of all the products  In addition, display the highest priced item and the lowest priced item

Lists  Python has such things called “lists”  Lists are denoted by brackets [ a, b, c, d ] and each item in the list is separated by commas  Lists can be stored and named as variables Example: x = [a, b, c, d]

Lists  One important thing to note about lists is that they can hold various data types all at once Example: list = [“name”, “word”, 1, 2, 3]

Nested Loops  A nested loop can be described as “a loop inside of a loop”  It’s the same idea as the nested “if” statements

Nested Loops  The inner loop of a nested loop will run through all of it’s iterations during each iteration of the outer loop  In other words, during one iteration of the outside loop, the inner loop will run it’s entire course (all iterations of the inner loop)  In order to find out the number of total iterations, multiply the number of iterations of all the loops

Practice - Times Table  Write a program that prints out the times table for the number 5 5 times 1 is 5 5 times 2 is 10 5 times 3 is 15 … 5 times 10 is 50

Practice - Times Table (Extended)  Write a program that prints out the times table for a range of numbers (user input) Range of numbers for times table (low): 2 High end of range: 4 2 times 1 is 2 3 times 1 is 3 4 times 1 is 4 2 times 2 is 4 3 times 2 is 6 4 times 2 is 8 2 times 3 is 6 3 times 3 is 9 4 times 3 is 12 … 2 times 10 is 20 3 times 10 is 30 4 times 10 is 40

Practice – It’s Time!  Write a program that prints out every single possible time value for the day, down to the second.  Output: 00:00:00 (12:00:00 am) 00:00:01 00:00:02 … 23:59:59 (11:59:59 pm)

Practice – Genesis Gradebook  Write a program that allows Mr. Seok to calculate the grade of each student in his class  First ask the user how many students are in his class  Then, for each student, ask the user for the score on each of three exams and calculate the average for each student  Then, print out the grades for each student

Practice – Genesis Gradebook How many students in your class? 6 For student 1: Test score 1: Test score 2: Test score 3: (repeat 6 times)

Practice – Genesis Gradebook Averages for Mr. Seok’s class Student 1: 95.4 % Student 2: 93.2 % Student 3: 88.6 % Student 4: 87.1 % Student 5: 80.0 Student 6: 76. 4%

Practice – Drawing  Write a program that outputs this image by using nested loops #

Practice – Pascal’s Triangle?  Write a program that reproduces this triangle of numbers by the use of nested loops

Practice – Prime Numbers  Write a program that finds and prints out all the prime number from 1 to  Format your output so that only 5 numbers will print per line. They should align in columns.