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

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

Chapter 4: Control Structures I (Selection)
Chapter 2 Flow of Control. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-2 Learning Objectives Boolean Expressions Building, Evaluating.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Conditional Statements Introduction to Computing Science and Programming I.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
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.
ECE122 L7: Conditional Statements February 20, 2007 ECE 122 Engineering Problem Solving with Java Lecture 7 Conditional Statements.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
BOOLEAN LOGIC CSC 171 FALL 2004 LECTURE 7. ASSIGNMENT Review Quiz # 2 Start reading Chapter 5.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
CS 1400 Jan 2007 Chapter 4, sections Relational operators Less than< Greater than> Less than or equal= Equal== Not equal!=
Thursday, December 14, 2006 “Would you tell me, please, which way I ought to go from here?” “That depends a good deal on where you want to get to,” said.
The If/Else Statement, Boolean Flags, and Menus Page 180
Geography 465 Assignments, Conditionals, and Loops.
Chapter 9 IF Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Chapter 2 Control.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
An Introduction to Programming Using Alice Boolean Logic.
Lecture 10 – Boolean expressions, if statements COMPSCI 101 Principles of Programming.
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.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
If Statements and Boolean Expressions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits:
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Boolean Expressions and Logical Operators CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington Credits:
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Decision Making CMSC 201 Chang (rev ).
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)
CS 139 – Programming Fundamentals Lecture 08A. Relational/comparison Operators Relational Operator Meaning > is greater than < is less than >= is greater.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
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.
Introduction to Decision Structures and Boolean Variables
Control Flow (Python) Dr. José M. Reyes Álamo.
Control Structures I Chapter 3
CPS120 Introduction to Computer Science
Sequence, Selection, Iteration The IF Statement
Lecture 3- Decision Structures
Topics The if Statement The if-else Statement Comparing Strings
Introduction To Robot Decision Making
Intro to Computer Science CS1510 Dr. Sarah Diesburg
JavaScript conditional
Topics The if Statement The if-else Statement Comparing Strings
Selection CIS 40 – Introduction to Programming in Python
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Bools and simple if statements
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Logical Operations In Matlab.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
More on Functions (Part 2)
Introduction To Robot Decision Making
Computer Science Core Concepts
Types, Truth, and Expressions (Part 2)
Boolean logic Taken from notes by Dr. Neil Moore
Understanding Conditions
ECS15 boolean.
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Computer Programming Basics
Types, Truth, and Expressions
Conditionals.
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions
Presentation transcript:

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

What type(s) would we use To represent your:  Weight  Height  Age  Name  Class status (freshman, sophomore, etc)  Gender  If you owe the university money  If you are taking classes this semester

Yesterday’s Lab – Main Concept Review First we looked at the idea of Conditionals and the basic six operators:  Less than: <  Greater than: >  Equal to: == (Not the same as =)  Not equal to: !=  Less than or equal to: <=  Greater than or equal to: >=

Yesterday’s Lab – Main Concept Review The results of a conditional operator is always a Boolean value.  Meaning ???  Either True or False

Boolean Expressions George Boole’s (mid-1800’s) mathematics of logical expressions Boolean expressions (conditions) have a value of True or False Conditions are the basis of choices in a computer, and, hence, are the basis of the appearance of intelligence in them.

What is True, and What is False True: any nonzero number or nonempty object. 1, 100, “hello”, [a,b] False: zero number or empty object. 0, “”,[ ] Special values called “True” and “False”, which are just stand-ins for 1 and 0. However, they print nicely (True or False)

Boolean Expression Every boolean expression has the form:  expression booleanOperator expression The result of evaluating something like the above is just True or False. Evaluating a boolean operation is a binary operation “if (a<b)” has two operands in expression However, remember what constitutes True or False in Python! “If (a)” will evaluate to True if a is non-zero!

Relational Operators Relational Operators have low preference < 3 – 2 (5 + 3) < (3 - 2) 8 < 1 False

Selection Then we looked at how conditionals are applied in selection statements. Selection is how programs make choices, and it is the process of making choices that provides a lot of the power of computing

Python if Statement if boolean_expression : suite evaluate the boolean_expression (True or False) if True, execute all statements in the suite

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.

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

Chained Comparisons In python, chained comparisons work just like you would expect in a mathematical expression: Given myInt has the value 5  0 <= myInt <= 5 True  0 10 False

Compound Expressions Logically 0 < X < 3 is actually (0 < X) and (X < 3) Logical Operators (lower case)  and  or  not