COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University 2010-2011.

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Advertisements

Computer programming Lecture 3. Lecture 3: Outline Program Looping [Kochan – chap.5] –The for Statement –Relational Operators –Nested for Loops –Increment.
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
Chapter 2: Algorithm Discovery and Design
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
Structured programming
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Repetition Statements.
Geography 465 Assignments, Conditionals, and Loops.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Introduction to Computer Programming in c
Chapter 2 Control. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. Repetition, quick overview.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Python Control Flow statements There are three control flow statements in Python - if, for and while.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Programming in Python Part III Dr. Fatma Cemile Serçe Atılım University
>>> # Fibonacci series:... # the sum of two elements defines the next... a, b = 0, 1 >>> while b < 10:... print b... a, b = b, a+b WHILE.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Chapter 8 Iteration Dept of Computer Engineering Khon Kaen University.
9/14/2015BCHB Edwards Introduction to Python BCHB Lecture 4.
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
September 7, 2004ICP: Chapter 3: Control Structures1 Introduction to Computer Programming Chapter 3: Control Structures Michael Scherger Department of.
REPETITION STATEMENTS - Part1  Also called LOOP STATEMENTS OR LOOP STRUCTURES 1 C++ Statements that repeat one or more actions while some condition is.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Introduction to Computing Using Python Repetition: the for loop  Execution control structures  for loop – iterating over a sequence  range() function.
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.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Engineering Computing I Chapter 3 Control Flow. Chapter 3 - Control Flow The control-flow of a language specify the order in which computations are performed.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
1 CSC103: Introduction to Computer and Programming Lecture No 9.
Repetition Looping. Types for while do..while for The for loop allows you to iterate through a variable for a specific range of values. You must supply.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Introduction to Python
Control Flow (Python) Dr. José M. Reyes Álamo.
Python: Control Structures
Think What will be the output?
Ch 7: JavaScript Control Statements I.
CS149D Elements of Computer Science
3 Control Statements:.
More Looping Structures
Repetition Control Structure
CMPT 102 Introduction to Scientific Computer Programming
3. Decision Structures Rocky K. C. Chang 19 September 2018
Introduction to Programming Using Python PART 2
Introduction to Python
While loops Genome 559: Introduction to Statistical and Computational Genomics Prof. William Stafford Noble.
Computer Science Core Concepts
Introduction to Python
Introduction to Computer Science
Repetition (While Loop) LAB 9
Python While Loops.
More Looping Structures
CSE 231 Lab 2.
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
REPETITION Why Repetition?
LOOP Basics.
Presentation transcript:

COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University

' if ' statement; block structure Block structure is determined by indentation if (condition): action1 if (condition): action1 elif (condition): action2 if (condition): action1 elif (condition): action2 else: action3 if (condition): action1 elif (condition): action2 elif (condition): action3 else: action3 if (condition): action1 else: action2

Exercise

Loops Loop is a statement or group of statements that execute repeatedly until a terminating condition is satisfied Infinite loop: A loop in which the terminating condition is never satisfied

while Statement Repetition of a block of statements Loop until test becomes false, or 'break‘ Explanation: “While n is greater than 0, continue displaying the value of n and then reducing the value of n by 1. When you get to 0, display the word End!”

while Statement (cont.) What are the outputs of the following programs?

for Loop Repetition of a block of statements Explanation: The loop continues until no characters are left and prints each character.

Exercise What is the output of the following program? The output :

Built-in functions 'range(..)' It is used to terate over a sequence of numbers: Examples: range(10): generates a list of 10 values starting from 0 and incrementing by value 1 (Note that 10 is not included) [0,1,2,3,4,5,6,7,8,9] range(0, 10, 2): generates values between 1 and 10 with increment value (or step value) 2 [0,2,4,6,8]

Exercise

Exercise 2 Write a program which prints the odd numbers between 1 and 150 (150 is not included)

Exercise 3 Write a program which prints the sum of numbers between 1 and 50 (50 is not included)

Exercise 4 Write a program which prints the prime numbers between 2 and 100 (100 is not included)