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)
If Statements & Relational Operators Programming.
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.
Geography 465 Assignments, Conditionals, and Loops.
Chapter 9 IF Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
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
CPS120: Introduction to Computer Science Decision Making in Programs.
CMSC 104, Version 8/061L11Relational&LogicalOps.ppt Relational and Logical Operators Topics Relational Operators and Expressions The if Statement The if-else.
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.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
1 Programming in C++ Dale/Weems/Headington Chapter 5 Conditions, Logical Expressions.
Decision Making CMSC 201. Overview Today we will learn about: Boolean expressions Decision making.
IB Computer Science – Logic
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.
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)
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
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
CPS120 Introduction to Computer Science
Sequence, Selection, Iteration The IF Statement
A mechanism for deciding whether an action should be taken
Topics The if Statement The if-else Statement Comparing Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
JavaScript conditional
Topics The if Statement The if-else Statement Comparing Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Bools and simple if statements
Types, Truth, and Expressions (Part 2)
Relational Operators Operator Meaning < Less than > Greater than
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Computer Science 210 Computer Organization
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction To Robot Decision Making
Computer Science Core Concepts
Types, Truth, and Expressions (Part 2)
Expressions.
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 (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

Truth Tables

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