Types, Truth, and Expressions (Part 2)

Slides:



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

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.
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.
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Python Programming Language
Conditional Statements Introduction to Computing Science and Programming I.
The If/Else Statement, Boolean Flags, and Menus Page 180
Decision Making George Mason University. Today’s topics 2 Review of Chapter 2: Decision Making Go over exercises Decision making in Python.
Decisions in Python elif. A new keyword elif A contraction of “else if” Used to tie two if statements (or more) together into one structure Syntax – elif,
Line Continuation, Output Formatting, and Decision Structures CS303E: Elements of Computers and Programming.
Chapter 2 Control.
Python Control Flow statements There are three control flow statements in Python - if, for and while.
Branching and Conditions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
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.
Decision Making CMSC 201. Overview Today we will learn about: Boolean expressions Decision making.
Python Conditionals chapter 5
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
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?
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.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
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.
If statement.  It is made up of three main components:  The keyword itself,  an expression that is tested for its truth value,  and a code suite to.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Control Flow (Python) Dr. José M. Reyes Álamo.
Chapter 3 Selection Statements
Introduction to Python
Making Choices with if Statements
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Upsorn Praphamontripong CS 1110 Introduction to Programming Fall 2016
Thinking about programming
Logical Operators and While Loops
More Repetition While and For Loops Sentinel-Controlled Loops
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Selection CIS 40 – Introduction to Programming in Python
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lists – Indexing and Sorting
Types, Truth, and Expressions (Part 2)
String Encodings and Penny Math
Types, Truth, and Expressions (Part 2)
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
More on Functions (Part 2)
Lists – Indexing and Sorting
CS 1111 Introduction to Programming Spring 2019
Intro to Nested Looping
Computer Science Core Concepts
Nate Brunelle Today: Conditional Decision Statements
Types, Truth, and Expressions (Part 2)
Python Programming Language
Logical Operators and While Loops
Understanding Conditions
Nate Brunelle Today: Conditional Decision Statements
Thinking about programming
CHAPTER 5: Control Flow Tools (if statement)
Lists – Indexing and Sorting
String Encodings and Penny Math
Types, Truth, and Expressions
Nate Brunelle Today: Conditional Decision Statements
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions
Presentation transcript:

Types, Truth, and Expressions (Part 2) Intro to Computer Science CS1510 Dr. Sarah Diesburg

Observations from PA 1 Variable names matter (don’t call it startingMileageStr when it contains a number) Import math? Why would you say float(2.2) Do your own work!

Review : Python if Statement if <expression> : suite Evaluate the expression to a Boolean value (True or False) if True, execute all statements in the suite

Review : Warning About Indentation Elements of the “suite” must all be indented the same number of spaces/tabs Python only recognizes suites when they are indented the same “distance” You must be careful to get the indentation right to get suites right.

Let’s test your knowledge Look at #1-4 in my questions.py program… Which letters are printed? A B A and B Neither

Python Selection The process is: evaluate the boolean if boolean expression: suite1 else: suite2 The process is: evaluate the boolean if True, run suite1 if False, run suite2

Let’s test your knowledge Let’s look at statements with if, elif, else Problems #5-9 : Which letters are printed? A B A and B Neither

Python Selection The process is: evaluate expression1 if boolean expression1: suite1 elif expression2: suite2 The process is: evaluate expression1 if True, run suite1 If False, evaluate expression 2 if True, run suite2

Python Selection – All Together if boolean expression1: suite1 elif boolean expression2: suite2 #(as many elif’s as you want) else: suiteLast

if, elif, else, the Process Evaluate boolean expressions until: The boolean expression returns True None of the boolean expressions return True If a boolean returns True, run the corresponding suite. Skip the rest of the if If no boolean returns True, run the else suite, the default suite