Python break,continue and pass Statements. The break Statement: for letter in 'Python': # First Example if letter == 'h': break print 'Current Letter.

Slides:



Advertisements
Similar presentations
ICE1341 Programming Languages Spring 2005 Lecture #13 Lecture #13 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Advertisements

JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
Numbers. Number data types store numeric values They are immutable data types, which means that changing the value of a number data type results in a.
ECS15 for and sequence. Comments  Another way to repeat.
Homework Read pages 304 – 309 Page 310: 1, 6, 8, 9, 15, 17, 23-26, 28-31, 44, 51, 52, 57, 58, 65, 66, 67, 69, 70, 71, 75, 77, 79, 81, 84, 86, 89, 90, 92,
Chapter 2 Writing Simple Programs
Intro to Python Paul Martin. History Designed by Guido van Rossum Goal: “Combine remarkable power with very clear syntax” Very popular in science labs.
Lesson Objective: I can…
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
Python Control of Flow.
Prime Factorization.
Python quick start guide
4. Python - Basic Operators
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Programming Training Main Points: - Python Statements - Problems with selections.
Python Control Flow statements There are three control flow statements in Python - if, for and while.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
1 CSCE 1030 Computer Science 1 Control Statements in Java.
Chapter 1. Objectives To provide examples of computer science in the real world To provide an overview of common problem- solving strategies To introduce.
Lesson 1.7 Dividing Integers Standards: NS 1.2 and AF 2.1 Objectives: Dividing Integers Evaluate variable expressions.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Python Basics. 2 Python History Late 1970s: programming language called ABC at the Centrum voor Wiskunde en Informatica in the Netherlands Audience included.
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
Algebra II Honors Problem of the Day Homework: p odds Solve the following: No real solution.
Prime Numbers and Factoring. Which expression is equal to 4x6? (a) 2 × 2 x 2 (b) 2 × 3 × 4 (c) 4 × 5 × 3 (d) 6 × 6.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
1 Looping Dale/Weems/Headington. 2 KA/JS/P Warning l Save your work often! l In the Khan Academy, JavaScript environment, infinite loops will lock up.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Lesson 10.2Logarithmic Functions Logarithm: Inverse of exponential functions. “log base 2 of 6” Ex: Domain: x>0 Range: all real numbers Inverse of exponential.
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.
Computer Science 101 For Statement. For-Statement The For-Statement is a loop statement that is especially convenient for loops that are to be executed.
 See pages 65 – 67 in your book  While loops are all around us ◦ Shampoo  Rinse, Lather, Repeat  While (Condition Is True) : ◦ Execute a block of.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
Learning Javascript From Mr Saem
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
1 float Data Type Data type that can hold numbers with decimal values – e.g. 3.14, 98.6 Floats can be used to represent many values: –Money (but see warning.
CS0004: Introduction to Programming
Lecture III Syntax ● Statements ● Output ● Variables ● Conditions ● Loops ● List Comprehension ● Function Calls ● Modules.
ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code.
Chapter 2 Writing Simple Programs
G. Pullaiah College of Engineering and Technology
Program design Program Design Process has 2 phases:
Main Points: - Python Statements - Problems with selections.
Loops in Java.
Evaluating Algebraic Expressions
Design & Technology Grade 7 Python
Basic operators - strings
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
Expressions and Control Flow in JavaScript
Ruth Anderson UW CSE 160 Spring 2018
Arithmetic operations, decisions and looping
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
CS1100 Computational Engineering
Decision Structures, String Comparison, Nested Structures
Complex Numbers Real Numbers Imaginary Numbers Rational Numbers
A function with one argument
Suggested Layout ** Designed to be printed on white A3 paper.
Introduction to Programming Using Python PART 2
(more) Python.
Python Basics with Jupyter Notebook
EASY SUBSTITUTION.
Repetition (While Loop) LAB 9
REPETITION Why Repetition?
LOOP Basics.
Control Structures.
Control flow: Loops UW CSE 160.
Data Types and Expressions
Presentation transcript:

Python break,continue and pass Statements

The break Statement: for letter in 'Python': # First Example if letter == 'h': break print 'Current Letter :', letter var = 10 # Second Example while var > 0: print 'Current variable value :', var var = var -1 if var == 5: break print "Good bye!" Current Letter : P Current Letter : y Current Letter : t Current variable value : 10 Current variable value : 9 Current variable value : 8 Current variable value : 7 Current variable value : 6 Good bye!

The continue Statement: for letter in 'Python': # First Example if letter == 'h': continue print 'Current Letter :', letter var = 10 # Second Example while var > 0: print 'Current variable value :', var var = var -1 if var == 5: continue print "Good bye!"

The else Statement Used with Loops for num in range(10,20): #to iterate between 10 to 20 for i in range(2,num): #to iterate on the factors of the number if num%i == 0: #to determine the first factor j=num/i #to calculate the second factor print '%d equals %d * %d' % (num,i,j) break #to move to the next number, the #first FOR else: # else part of the loop print num, 'is a prime number'

The pass Statement: for letter in 'Python': if letter == 'h': pass print 'This is pass block' print 'Current Letter :', letter print "Good bye!" Current Letter : P Current Letter : y Current Letter : t This is pass block Current Letter : h Current Letter : o Current Letter : n Good bye!

Number Type Conversion: Python converts numbers internally in an expression containing mixed types to a common type for evaluation. But sometimes, you'll need to coerce a number explicitly from one type to another to satisfy the requirements of an operator or function parameter.  Type int(x)to convert x to a plain integer.  Type long(x) to convert x to a long integer.  Type float(x) to convert x to a floating-point number.  Type complex(x) to convert x to a complex number with real part x and imaginary part zero.  Type complex(x, y) to convert x and y to a complex number with real part x and imaginary part y. x and y are numeric expressions