Introduction to Computer Science

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

Chapter 4 Ch 1 – Introduction to Computers and Java Flow of Control Loops 1.
Looping Structures: Do Loops
CS0004: Introduction to Programming Repetition – Do Loops.
Python for Informatics: Exploring Information
CS001 Introduction to Programming Day 3 Sujana Jyothi
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Chapter 2: Algorithm Discovery and Design
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Complexity (Running Time)
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
CS0007: Introduction to Computer Programming Introduction to Arrays.
Loops and Iteration Chapter 5 Python for Informatics: Exploring Information
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science, Java Version, Second Edition.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
While Loops CMSC 201. Overview Today we will learn about: Looping Structures While loops.
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.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Fundamentals of Algorithms MCS - 2 Lecture # 15. Bubble Sort.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Loops and Iteration Chapter 5 Python for Informatics: Exploring Information
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
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.
Loop Structures and Booleans Zelle - Chapter 8 Charles Severance - Textbook: Python Programming: An Introduction to Computer Science,
FOP: While Loops.
CS161 Introduction to Computer Science
Loops and Iteration Chapter 5 Python for Everybody
Think What will be the output?
Numeracy in Science – Standard Form
Python - Loops and Iteration
Iterations Programming Condition Controlled Loops (WHILE Loop)
While Loops (Iteration 2)
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Recursion Chapter 11.
Introduction to pseudocode
Loop Structures and Booleans Zelle - Chapter 8
Repetition Structures
CS150 Introduction to Computer Science 1
Global Challenge Walking for Water Lesson 2.
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
For Loops (Iteration 1) Programming Guides.
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
More Repetition While and For loop variations
FLUENCY WITH INFORMATION TECNOLOGY
Global Challenge Walking for Water Lesson 2.
Every number has its place!
Introduction to Computer Science
Introduction to Computer Science
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Introduction to Computer Science
Global Challenge Walking for Water Lesson 2.
The structure of programming
Thinking procedurally
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Global Challenge Walking for Water Lesson 2.
CMPT 120 Lecture 16 – Unit 3 – Graphics and Animation
Global Challenge Walking for Water Lesson 2.
Global Challenge Walking for Water Lesson 2.
Presentation transcript:

Introduction to Computer Science Programming with Python

Loops & Iteration Chapter 5 - Finding the Largest Value

Looping Through a Set

What is the Largest Number? Imagine we have a list of 1 billion numbers, and our task is to find the largest number How would you do this?

What is the Largest Number? Imagine we have a list of 1 billion numbers, and our task is to find the largest number How would you do this? Since computers can perform repetitive tasks in an extremely fast manner, the optimal and most efficient way is to let the computer find the largest number Write a program that loops through the list and find the largest number for loop Counter (in) And simply, a list of numbers Conditional statement to compare numbers

What is the Largest Number? In this example, we will not use 1 billion numbers so we can debug the code quicker. But, next, we will try this on larger scale Given list [9, 41, 12, 3, 74, 15] Initialize a variable named “largest_so_far” and initialize it with -1, which indicates I have not seen any numbers so far If the next number on the list is 9, and it is greater than -1, so, the largest so far is 9 However, we keep looping until the end of the list and whenever we find a greater number, we update the value of largest_so_far Lets code! Happy coding!

Finding the Largest value

How about the smallest Value? Tip, just a minor change

How about the smallest Value? Tip, just a minor change