PYTHON IF-STATEMENTS. What you know If something is true, then something happens Example If you heat water to 100 degrees Celsius, then it boils If it.

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

IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
The If Then Else Statement Using JavaScript TIP The If Statement is the fundamental control structure that allows branches in the flow of control in a.
3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
Python Programming Language
CS-1010 Dr. Mark L. Hornick 1 Selection Statements and conditional expressions.
Python Magic Select a Lesson: Why Learn to Code? Basic Python Syntax
Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Chapter 6 Horstmann Programs that make decisions: the IF command.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Introduction to Programming with Java, for Beginners Control Structures.
Intro to Java while loops pseudocode. 1 A “Loop” A simple but powerful mechanism for “making lots of things happen!” Performs a statement (or block) over.
1 Conditionals In many cases we want our program to make a decision about whether a piece of code should be executed or not, based on the truth of a condition.
Flow control 1: if-statements (Liang 72-80) if(radius < 0) { System.out.println(“cannot get area: radius below zero”); } else { double area = radius *
Introduction to Programming with Java, for Beginners Conditionals (if statements)
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Decision Making George Mason University. Today’s topics 2 Review of Chapter 2: Decision Making Go over exercises Decision making in Python.
Do it now activity Correct the 8 syntax errors: Age = input(“How old are you?” If age = 10 Print(You are 10”) else: print(“You are not 10”)
Basic Object-Oriented Concepts
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.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Decision Making CMSC 201. Overview Today we will learn about: Boolean expressions Decision making.
Chapter 3: Branching and Program Flow CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
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.
Boolean Expressions and Logical Operators CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington Credits:
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?
Decision Making CMSC 201 Chang (rev ).
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 3 Decision Trees Conditionals.
Lesson thirteen Conditional Statement "if- else" ©
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.
Computer Science 101 If Statement. Python Relational Operators.
Control Structures If Else Statement. S E S Q C E N U …consecutive steps (or groups of steps) processed one after another in the order that they arise.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
PYTHON WHILE LOOPS. What you know While something is true, repeat your action(s) Example: While you are not facing a wall, walk forward While you are.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Temperature Water Boil Freeze Celsius 100 o C 0 o C Fahren. 212 o F 32 o F 0 o F Kelvins K K 0 K Not degrees K What 0 o F and 0 K mean Formulas.
Conditionals. What is Conditional? “Something will only be done if something else happens first” (Longman)
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
Introduction to C++ Programming Language
Selection and Python Syntax
Welcome to Computer Science Jeopardy
Basic operators - strings
Absolute zero is simply a linear extrapolation used to locate at point at which gasses reach zero pressure. True False.
CSc 110, Spring 2017 Lecture 8: input; if/else
Lesson 8: Boolean Expressions and "if" Statements
ICS 3U Tuesday, September 21st.
Selection CSCE 121 J. Michael Moore.
CSc 110, Autumn 2016 Lecture 9: input; if/else
Sridhar Narayan Java Basics Sridhar Narayan
Flow Control Statements
Conditional Logic Presentation Name Course Name
Python Programming Language
Selection Structures: Single-alternative
Nate Brunelle Today: Conditional Decision Statements
Programming In Lesson 4.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
CHAPTER 5: Control Flow Tools (if statement)
Python While Loops.
How to allow the program to know when to stop a loop.
Data Types and Expressions
Presentation transcript:

PYTHON IF-STATEMENTS

What you know If something is true, then something happens Example If you heat water to 100 degrees Celsius, then it boils If it rains, then the game is delayed If I forget to eat, then I will be hungry

Flow of an if-statement if

Booleans Values of True or False Some expressions simplify/evaluate to Booleans (True/False) Examples: 5 > 0 10 < 100 If-statement conditions need Booleans

Python If-statement Template if CONDITION: #code in if block What’s happening above? If the CONDITION is True, then the code in the if block will run

Example age = int(input(“How old are you?”)) if age > 15: print(“You allowed to drive”)

What if I wanted to do something else else if

Python if-else statement Template if CONDITION: #code in if block else: #code in else block What’s happening above? If the CONDITION is True, then the code in the if block will run, else, the code in the else block runs (else runs when the if is False)

Example age = int(input(“How old are you?”)) if age < 21: print(“You are not allowed to vote”) else: print(“You can vote!”)