Selection (IF Statements)

Slides:



Advertisements
Similar presentations
Selection Statements Make a decision based on conditions Allows the computer to be intelligent.
Advertisements

Python - Selection Starter
If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Variables i)Numeric Variable ii)String Variable
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
CS 111: Introduction to Programming Midterm Exam NAME _________________ UIN __________________ 10/30/08 1.Who is our hero? 2.Why is this person our hero?
Geography 465 Assignments, Conditionals, and Loops.
Adding Automated Functionality to Office Applications.
Greater than or equal? A lesson on math language A lesson on math language.
From Scratch to Python Learn to program like the big boys / girls!
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
INTRODUCTION TO PYTHON. 1. The 5 operators in Python are: + - * / %
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.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Flowcharts! January 13, 2005 These are today’s notes! Do you think we will get more snow?
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.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
Python Selection. All the programs you have been developing so far have been sequential, this means that each instruction is executed in a set order.
Writing and Graphing Inequalities Because “I
Python - Selection Selection means selecting (or choosing) what to do next. Should I cycle to school, or ask for a lift? If it’s a sunny day I might cycle.
InequalitiesInequalities. An inequality is like an equation, but instead of an equal sign (=) it has one of these signs: Inequalities work like equations,
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Lesson 1.4 Equations and Inequalities Goal: To learn how to solve equations and check solutions of equations and inequalities.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
GCSE Computing: Programming GCSE Programming Remembering Python.
Python Lesson 2.
Lesson 7-3 Pages Inequalities PA Lesson Check 7-2.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Programming In Python. Starter Using the internet… Find what a programming language is.
Input, Output and Variables GCSE Computer Science – Python.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
PYTHON PROGRAMMING Year 9. Objective and Outcome Teaching Objective Today we will look at conditional statements in order to understand how programs can.
Introduction to Decision Structures and Boolean Variables
GCSE COMPUTER SCIENCE Practical Programming using Python
what is computer programming?
Whatcha doin'? Aims: To start using Python. To understand loops.
3.1 Fundamentals of algorithms
< > < < Writing Inequalities < < < >.
Lesson 4 - Challenges.
Debugging and Random Numbers
IF statements.
While Loops (Iteration 2)
X-STANDARD MATHEMATICS ONE MARK QUESTIONS
An Introduction to Python
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Algebra Vocabulary.
Story time Task 5 Computer Programming Gray , Calibri 24
Comparing Strings – How to
Statistics and Probability-Part 3
Spot the bug!.
Visual Basic – Decision Statements
Selection Statements.
Introduction to Decision Structures and Boolean Variables
Inputs and Variables Programming Guides.
Open Sentences.
Conditional Logic Presentation Name Course Name
Learning Intention I will learn about programming using selection (making choices) with one condition.
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Flowcharts and Pseudo Code
Relational Operators.
Comparing floating point numbers
Inequalities When comparing the numbers 7 and 4
Chapter 3: Selection Structures: Making Decisions
Inequalities When comparing the numbers 7 and 4
Python Selection.
Hardware is… Software is…
Presentation transcript:

Selection (IF Statements) Programming Guides

Selection (IF Statements) If we want the computer to make a decision based on our input we use “selection”. Selection uses If – Else statements Outcome 1 Outcome 2

Selection (IF Statements) What is your age? Example of a virtual barman program deciding whether to serve a customer: IF age > 17 do this ELSE, do that “What can I get you?” “Go home boy!” IF – ELSE statements allow programs to make decisions based on certain conditions occurring.

Selection (IF Statements) Colons are needed at the end of each IF and ELSE statement When you use selection statements you must indent accordingly.

Selection (IF Statements) In IF statements we will be looking to compare some data. We might want to see if a variable is equal to a number or a piece of text. We might want to see if a variable contains a number greater than another Or contains a number smaller than another. In python we use certain symbols to compare data. To see if something is mathematically equal to another we use a double equals sign (==) To see if a variable contains a number greater than another we use the greater than symbol (>) To see if a variable contains a number smaller than another we use the less than symbol (<) Relational Operators How They Compare = (or ==) Is equal to <> (or !=) Is not equal to < Is less than > Is greater than <= Is less than or equal to >= Is greater than or equal to

Selection (IF Statements) You can compare the contents of two variables in an IF statement. You can also compare the contents of a variable against some ‘hard coded’ data. Remember, if it’s a string, you must use speech marks!