Types, Truth, and Expressions

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.
Top-Down Design CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
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.
Line Continuation, Output Formatting, and Decision Structures CS303E: Elements of Computers and Programming.
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.
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.
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.
Logical Operators, Boolean Variables, Random Numbers This template was just too good to let go in one day!
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
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.
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.
Chapter 3 Selection Statements
Introduction to Python
Line Continuation, Output Formatting, and Decision Structures
Making Choices with if Statements
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Thinking about programming
Logical Operators and While Loops
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Line Continuation, Output Formatting, and Decision Structures
Selection CIS 40 – Introduction to Programming in Python
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lists – Indexing and Sorting
Bools and simple if statements
Types, Truth, and Expressions (Part 2)
String Encodings and Penny Math
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Programming Using Python PART 2
More on Functions (Part 2)
Lists – Indexing and Sorting
CS 1111 Introduction to Programming Spring 2019
Nate Brunelle Today: Conditional Decision Statements
Types, Truth, and Expressions (Part 2)
Logical Operators and While Loops
Boolean logic Taken from notes by Dr. Neil Moore
Understanding Conditions
Introduction to Python
Nate Brunelle Today: Conditional Decision Statements
Thinking about programming
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Thinking about programming
Lists – Indexing and Sorting
String Encodings and Penny Math
Nate Brunelle Today: Conditional Decision Statements
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions
Presentation transcript:

Types, Truth, and Expressions Intro to Computer Science CS1510 Dr. Sarah Diesburg

Homework Hints From now on can use CONSTANT_NAMES for constants No line wrap

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

Questions about PA02??

Line Wrap Some rules Strings must be closed in the line in which they start Adding a backslash at the end of the line tells python that the command is continued on the end of the line

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 Let‘s look at #1-4 in my questions.py program…

Let’s test your knowledge Problems #1-4 : Which letters are printed? A B A and B Neither

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, Round 2 if boolean expression: suite1 else: suite2 The process is: evaluate the boolean if True, run suite1 if False, run suite2

Python Selection, Round 3 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, Round 3 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