Intro to Nested Looping

Slides:



Advertisements
Similar presentations
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Advertisements

1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
CS 280 Data Structures Professor John Peterson. Big O Notation We use a mathematical notation called “Big O” to talk about the performance of an algorithm.
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.
General Programming Introduction to Computing Science and Programming I.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Designing Programs with Branches CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1 CS 1430: Programming in C++. 2 Input: Input ends with -1 Sentinel-Controlled Loop Input: Input begins with.
Textbook Problem Java – An Introduction to Problem Solving & Programming, Walter Savitch, pp.219, Problem 08.
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CS 100 Introduction to Computing Seminar October 7, 2015.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Iterative Structures (Loops) CS 1401 Spring 2013 Shirley Moore, Instructor February 28, 2013.
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.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Introduction to Computing Science and Programming I
More on Functions (Part 2)
CS 1430: Programming in C++ No time to cover HiC.
C++ Programming: CS150 For.
Chapter 4: Control Structures
Week 4 – Chapter 3 Repetition.
Chapter 6: Conditional Statements and Loops
Lecture 07 More Repetition Richard Gesick.
Computer Science 101 While Statement.
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
More Repetition While and For Loops Sentinel-Controlled Loops
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
More Nested Loops and Lab 5
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to pseudocode
Intro to Nested Looping
String Encodings and Penny Math
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Types, Truth, and Expressions (Part 2)
Count Controlled Loops (Nested)
Intro to Nested Looping
Introduction to Computer Programming
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Iteration: Beyond the Basic PERFORM
INC 161 , CPE 100 Computer Programming
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
More on Functions (Part 2)
More on Functions (Part 2)
Intro to Nested Looping
CS150 Introduction to Computer Science 1
Types, Truth, and Expressions (Part 2)
Topics Introduction to Repetition Structures
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Thinking about programming
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Types, Truth, and Expressions
Introduction to Strings
Hossain Shahriar CISC 101: Fall 2011 Hossain Shahriar
REPETITION Why Repetition?
Control Structures.
Types, Truth, and Expressions
Presentation transcript:

Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg

Some Things From PA02 BMI These were continuous regions. Set up your code to handle all areas…

Some Things From PA02 BMI While this is valid mathematically, it is bad form in programming languages. And it causes real problems when not set up properly.

Some Things From PA02 BMI Recognize that these are four related categories. This makes it much easier to use if/elif/else.

Some Things From PA02 BMI Recognize that these are four related categories. This makes it much easier to use if/elif/else.

Some Things From PA02 BMI Recognize that these are four related categories. This makes it much easier to use if/elif/else.

Some Things From PA02 Watch for messages that can only be printed under certain circumstances The triangle program should not print that something is an invalid triangle AND a right triangle…

Nesting Nesting means to place one code structure inside of another Nested if statements If (a<1): if (a==0): print(“Hey, this is zero”) else: print(“This is a negative number”)

Nested Loops We can also nest loops Can be very powerful, but tricky!

The idea of nested looping for x in range(1,4): for y in range(1,5): print (x, '*' , y , '=' , (x*y)) How many times will this print??

Finding Out if a Number is Prime An integer, N, is prime if it is not evenly divisible by any of the numbers from 2 to N-1

Finding Out if a Number is Prime Is 41 a prime number? Is 77 a prime number?

Finding Out if a Number is Prime Is 413 a prime number? Is 419 a prime number?

Let’s Write a Design Paragraph Inputs? Steps to calculate result Outputs?

Finding Out if a Number is Prime Write a program that: Asks for an integer greater than 2 Keeps prompting until it gets one Checks the numbers from 2 to N-1 to see if N is evenly divisible by that number Prints a message either way.

So how would we change this… To print information about all of the numbers from 2 to 100? Nested Looping