Multiple Selections (ELIF Statements)

Slides:



Advertisements
Similar presentations
Lesson 6: Boolean and If Statements Computer Science 1 Mr. Bernstein.
Advertisements

If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Conditional Statements Introduction to Computing Science and Programming I.
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.
Designing Programs with Branches CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
The Other Face Chapter 15. What documentation is required? ► Different levels of documentation are required for the casual user of a program, for the.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 3 Decision Trees Conditionals.
A Level Computing#BristolMet Session Objectives#U2 S3 MUST use/read programme flow charts accurately SHOULD adapt the calculator programme to include a.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
PYTHON PROGRAMMING Year 9. Objective and Outcome Teaching Objective Today we will look at conditional statements in order to understand how programs can.
Starter What does the following code do?
Handling Exceptionally Sticky Problems
Making Choices with if Statements
Repetition Structures Chapter 9
Lesson 4 - Challenges.
Selection and Python Syntax
Python: Control Structures
Topics: jGRASP editor ideosyncrasies assert debugger.
Computer Programming Fundamentals
IF statements.
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
If, else, elif.
Selection UCT Department of Computer Science Computer Science 1015F
Lesson 9: "if-else-if" and Conditional Logic
Using the Priming Read Priming read (or priming input):
Selection By Ramin && Taimoor
Ruth Anderson UW CSE 160 Winter 2017
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Learning to Program in Python
Conditional Statements
More Selections BIS1523 – Lecture 9.
Procedures Programming Guides.
Selection CIS 40 – Introduction to Programming in Python
Python - Conditional Execution
Validations and Error Handling
Decision Structures, String Comparison, Nested Structures
Lesson 3. 1 How do we interpret and represent functions. Standards F
Understanding the Three Basic Structures
Ruth Anderson UW CSE 140 Winter 2014
Topic 1: Problem Solving
Loops CIS 40 – Introduction to Programming in Python
Practice with loops! What is the output of each function below?
Coding Concepts (Basics)
Patterns to KNOW.
Program Flow Control Selection & repetition
What does this do? def revList(L): if len(L) < = 1: return L x = L[0] LR = revList(L[1:]) return LR + x.
Three Special Structures – Case, Do While, and Do Until
Visual Basic – Decision Statements
Function notation.
Conditionals.
If Statements.
Suppose I want to add all the even integers from 1 to 100 (inclusive)
A LESSON IN LOOPING What is a loop?
Python Basics with Jupyter Notebook
Nate Brunelle Today: Conditional Decision Statements
CHAPTER 5: Control Flow Tools (if statement)
Handling Exceptionally Sticky Problems
Chapter 3: Selection Structures: Making Decisions
Control Flow statements
Michael Ernst UW CSE 190p Summer 2012
The IF Revisited A few more things Copyright © Curt Hill.
Challenge Guide Grade Code Type Slides
Presentation transcript:

Multiple Selections (ELIF Statements) Programming Guides

Multiple Selections (ELIF Statements) Often we will want our programs to make a decision based on a range of different conditions. The issue with IF-ELSE statements is that they only allow us to check against one condition and provide only two possible pathways for the program. To check a range of different conditions enabling our program to take one of many different pathways we can use ELIF statements. They are organised in this way: IF this condition is true: run this code ELIF this condition is true: run this code instead ***more ELIF statements if we need*** ELSE: ELIF means ELSE-IF

Multiple Selections (ELIF Statements) Here is an example of a program using the ‘ELIF’ construct: Notice the OPERATORS! Notice the INDENTATIONS! Notice the ELSE…could this program have issues?? …yes! If the user types in any number (other than 1 or 2), the program would always print the last statement.

Multiple Selections (ELIF Statements) Validations The process of ensuring that the user always gets the right output in response to the input they give is called validation. Here is an example of the previous program and a newer version which seeks to validate the entries somewhat.