Types, Truth, and Expressions (Part 2)

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

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.
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.
Geography 465 Assignments, Conditionals, and Loops.
Line Continuation, Output Formatting, and Decision Structures CS303E: Elements of Computers and Programming.
Chapter 2 Control.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Decision Structures and Boolean Logic
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
CPS120: Introduction to Computer Science Decision Making in Programs.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Decisions in Python Bools and simple if statements.
Decision Structures, String Comparison, Nested Structures
Boolean Expressions and Logical Operators CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington Credits:
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.
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.
 Type Called bool  Bool has only two possible values: True and False.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Control Flow (Python) Dr. José M. Reyes Álamo.
Control Structures I Chapter 3
Chapter 3 Selection Statements
Line Continuation, Output Formatting, and Decision Structures
Selection (also known as Branching) Jumail Bin Taliba by
Making Choices with if Statements
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lecture 3- Decision Structures
IF statements.
Topics The if Statement The if-else Statement Comparing Strings
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
CSC115 Introduction to Computer Programming
Thinking about programming
Logical Operators and While Loops
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Conditional Statements
Topics The if Statement The if-else Statement Comparing Strings
Line Continuation, Output Formatting, and Decision Structures
Selection CIS 40 – Introduction to Programming in Python
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Conditions and Ifs BIS1523 – Lecture 8.
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)
Chapter 7 Conditional Statements
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Programming Using Python PART 2
CS 1111 Introduction to Programming Spring 2019
Types, Truth, and Expressions (Part 2)
Python Programming Language
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
Class 13 function example unstring if if else if elif else
Logical Operators and While Loops
Boolean logic Taken from notes by Dr. Neil Moore
Understanding Conditions
Thinking about programming
String Encodings and Penny Math
Types, Truth, and Expressions
Nate Brunelle Today: Conditional Decision Statements
Types, Truth, and Expressions
Presentation transcript:

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

Issues from PA01 Turn in your paperwork, stapled, in order given on assignment Include a header block Which includes your full name Proper format for variableNames From now on can use CONSTANT_NAMES for constants File names matter – give it the name that was requested No line wrap

Issues from PA01 Make sure you READ directions The directions told you what order the data should be given Days, hours, minutes, seconds Test your code! I specifically gave you an example for each program. It better work on this. But, this wasn’t enough examples to guarantee everything worked. What other things should you test?

Observations from PA 1 Variable names matter (don’t call it minuteStr 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 Reminder 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

Compound Expressions Logical Operators (lower case) and or not

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

Truth Tables

Truth Tables

Truth Tables

Truth Tables

Truth Tables

Chained Comparisons You are going to be tempted to write: 0 <= myInt <= 5 But you will need to be very careful

Compound Evaluation Logically 0 < X < 3 is actually (0 < X) and (X < 3) Evaluate using X with a value of 2: (0< X) and (X< 3) Parenthesis first: (True) and (True) Final value: True (Note: parentheses are not necessary in this case.)

Compound Evaluation BUT, I’ve seen students write: 3 < X < 0 Meaning they want to know if x is outside of that range. But this is actually (3 < X) and (X < 0) Evaluate using X with a value of 5: (3< X) and (X< 0) Parenthesis first: (True) and (False) Final value: False