ITEC 109 Lecture 16 Functions (3) Conditionals. Functions / Conditionals Review Functions –Parameters –Returns –Syntax –Scope.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 8 Fruitful Functions 05/02/09 Python Mini-Course: Day 2 - Lesson 8 1.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Python Programming Language
Lecture 12 – Loops – while loops COMPSCI 1 1 Principles of Programming.
Analysis And Algorithms CMSC 201. Search Sometimes, we use the location of a piece of information in a list to store information. If I have the list [4,
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
Main task -write me a program
Intro to Robots Conditionals and Recursion. Intro to Robots Modulus Two integer division operators - / and %. When dividing an integer by an integer we.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
TODAY’S LECTURE Review Chapter 2 Go over exercises.
Chapter 5 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved2/33 Conditionals and Loops Now we will examine programming statements.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
Chapter 9 IF Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Python quick start guide
Python.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Boolean expressions Conditional statements and expressions.
Looping Constructs “Here we go loop de loop, on a Saturday night” – Johnny Thunder “First I'm up, and then I'm down. Then my heart goes around and around.”
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.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 7 Conditionals and Loops 4/18/09 Python Mini-Course: Day 2 - Lesson 7.
Chapter 3: Branching and Program Flow CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
ITEC 109 Lecture 14/15 Strings + Functions. Review Strings –What can we do? –Why?
Decisions in Python Boolean functions. A Boolean function This is a function which returns a bool result (True or False). The function can certainly work.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CSI 3125, Preliminaries, page 1 Control Statements.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
Complex Branching Statements CSIS 1595: Fundamentals of Programming and Problem Solving 1.
ITEC 109 Lecture 18 Looping. Review Questions? Conditionals –if / elif / else –and / or / not.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Arrays and Loops. Learning Objectives By the end of this lecture, you should be able to: – Understand what a loop is – Appreciate the need for loops and.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
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.
Multi-Selection If-elsif Statement.  In fact, it’s everything in between  Yesterday we learned how to add a control statement that gave us two path.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
 Type Called bool  Bool has only two possible values: True and False.
Introduction to Python
Control Flow (Python) Dr. José M. Reyes Álamo.
Python 23 Mr. Husch.
C-Language Lecture By B.S.S.Tejesh, S.Neeraja
Creativity in Algorithms
Topic: Functions – Part 2
Adapted from slides by Marty Stepp and Stuart Reges
Boolean expressions Conditional statements and expressions
Mrs. Waller’s Class – Choose Your Own Adventure Story
Building Java Programs
Adapted from slides by Marty Stepp and Stuart Reges
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Unit 3 - The while Loop - Extending the Vic class - Examples
CS139 October 11, 2004.
Visual Basic – Decision Statements
Introduction to Python
Statement-Level Control Structures
Building Java Programs
Introduction to Python
Conditionals and Loops
Factoring if/else code
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Presentation transcript:

ITEC 109 Lecture 16 Functions (3) Conditionals

Functions / Conditionals Review Functions –Parameters –Returns –Syntax –Scope

Functions / Conditionals Objectives Review functions Examples Introduce iteration

Functions / Conditionals Functions Why use them? What is a parameter? What is a return value

Functions / Conditionals Example def fun1(): fun2() printNow("Done") def fun2(): printNow("Test") fun1()

Functions / Conditionals Example def fun1(var1,var2): return var1+var2 printNow("Done") def fun2(): return int(raw_input()) x = fun2() y = fun2() z = fun1(x,y) printNow(z)

Functions / Conditionals Example def mystery(var1): printNow(var1) if (var1 > 25): return; else: mystery(var1+1) mystery(1)

Functions / Conditionals Conditionals What is the purpose of if What is the purpose of elif What is the purpose of else What is the syntax for the three?

Functions / Conditionals Example If you shoot a cow Then you get steak

Functions / Conditionals Choose your own adventure Book where you make choices as you read Choices you make impact the story –Wildly rich –Horrible deaths If you decide to start back home, turn to page 4. If you decide to wait, turn to page 5.

Functions / Conditionals Priorities

Functions / Conditionals Visually First choice Second choice Last choice if (condition) { } else if (condition) { } else (condition) { } public static void main { //Code before //Code after } Only when if not met and condition is true

Functions / Conditionals Structure Expression (True or false) –All vars:,==, != Based on the word / expression a block of code gets executed

Functions / Conditionals Python First choice = if Second choice = elif Third choice = elif Last choice = else Linear progression Begins with if Ends with else

Functions / Conditionals Example var1=3 if (var1 > 3): printNow("1") elif (var1 < 3): printNow("2") else: printNow("3")

Functions / Conditionals Example x=3; y=4; if (x>3): printNow(“X is big”); elif (y <4): printNow(“Y is small”); elif (x == y): printNow(“Same”); else: printNow(“Can you see me now?”);

Functions / Conditionals Example Can you guess the number between 1-10 that I’m thinking of exercise Check to see if it is between 1 and 10 Then say Exact if it is 5, Higher than my choice if is above 5, Lower than my choice if it is less than 5

Functions / Conditionals Chaining total=3; max=3; sum=4; //Scanner code to read in the values if (total == max): if (total < sum): printNow(“T < S”); else: printNow(“ T = M < S”);

Functions / Conditionals Review Functions Conditionals