Intro to Nested Looping

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
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.
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
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.
CSCI-100 Introduction to Computing
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.
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.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
C++ Programming: CS150 For.
CS1371 Introduction to Computing for Engineers
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
Division Page 87 – 119.
More Nested Loops and Lab 5
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to pseudocode
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
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)
More Repetition While and For loop variations
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Thinking about programming
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Nested Looping
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 calculator program should not print that something is invalid AND calculate the answer…

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