Compound Conditionals

Slides:



Advertisements
Similar presentations
7.1Variable Notation.
Advertisements

Chapter 1 Section 3 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
SOLUTION EXAMPLE 1 A linear system with no solution Show that the linear system has no solution. 3x + 2y = 10 Equation 1 3x + 2y = 2 Equation 2 Graph the.
Repeating Actions While and For Loops
Introduction Solving inequalities is similar to solving equations. To find the solution to an inequality, use methods similar to those used in solving.
Integers and Introduction to Solving Equations
Presents Section 1.3 Inequalities and Absolute Value MB1 Track This section is prepared by M. Zalzali.
Lesson Objective: I can…
Step 1: Simplify Both Sides, if possible Distribute Combine like terms Step 2: Move the variable to one side Add or Subtract Like Term Step 3: Solve for.
Introduction While it may not be efficient to write out the justification for each step when solving equations, it is important to remember that the properties.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Lesson 8-1 Negative & Zero. Your Goal: Simplify expressions containing integer exponents.
Decision Structures and Boolean Logic
Variables Tutorial 3c variable A variable is any symbol that can be replaced with a number to solve a math problem. An open sentence has at least one.
Copyright 2013, 2010, 2007, Pearson, Education, Inc. Section 3.7 Switching Circuits.
Practice 1.2 Answers
1.4 Solving Equations ●A variable is a letter which represents an unknown number. Any letter can be used as a variable. ●An algebraic expression contains.
Open Sentences.
Copyright © 2010 Pearson Education, Inc. All rights reserved. 1.2 – Slide 1.
Semester 1 Final Review Lesson 1.1 Variables in Algebra Evaluate the variable expression when x = x.
TABLES AND VALUES Section 1.5. Open Sentence Equation.
Algebra Equations Lesson 1-7 Pages Equations An Equation is a sentence that contains an equals = sign. The equals = sign tells you that the expression.
InequalitiesInequalities. An inequality is like an equation, but instead of an equal sign (=) it has one of these signs: Inequalities work like equations,
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Chapter 1 Section 3. Objectives 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Evaluate algebraic expressions, given values for the variables.
1.3 Open Sentences A mathematical statement with one or more variables is called an open sentence. An open sentence is neither true nor false until the.
Lesson 1.4 Equations and Inequalities Goal: To learn how to solve equations and check solutions of equations and inequalities.
Operators.
4.4 Solving Multi-step Inequalities. 4.4 – Solving Multi-step Inequal. Goals / “I can…”  Solve multi-step inequalities with variables on one side  Solve.
Equations and Inequalities. Equation – A sentence stating that two qualities are equal. Includes a variable – 3x + 5 = 17 Equation variable The solution.
Intro to Inequalities Unit 4 Section 4.1. Definition A statement that a mathematical expression is greater than or less than another expression.
Chapter 4.  integer  negative sign  opposites  absolute value.
Opener: Find three consecutive odd integers whose sum is -63 Integer #1 = n Integer #2 = n + 2 Integer #3 = n + 4 (n) + (n + 2) + (n + 4) = -63 3n + 6.
Random Functions Selection Structure Comparison Operators Logical Operator
CprE 185: Intro to Problem Solving (using C)
Algebraic Expressions
Variables and Expressions
AND.
Graphing Inequalities
Truth Tables for Negation, Conjunction, and Disjunction
Solving Equations with the Variable on Each Side
Sequence, Selection, Iteration The IF Statement
CHAPTER 1.3 Solving Equations.
Where letters are numbers and numbers are letters!
2.4 & 2.5 Absolute Value Inequalities and Equations
1-5 Equations Goals: Solve equations with one variable
4 Chapter Chapter 2 Decimals.
Introduction to Algebra
Topics The if Statement The if-else Statement Comparing Strings
Introduction While it may not be efficient to write out the justification for each step when solving equations, it is important to remember that the properties.
Solving Linear Inequalities
Topics The if Statement The if-else Statement Comparing Strings
Logical Operators & Truth Tables.
Inequalities and Their Graphs
Solving Equations with Variables on Both Sides Day 2
Introduction Solving inequalities is similar to solving equations. To find the solution to an inequality, use methods similar to those used in solving.
3-1 Inequalities and Their Graphs
Selection Statements.
LINEAR EQUATIONS.
Section 3.7 Switching Circuits
Relational Operators.
Chapter 1 Section 3.
Section 3.2 Truth Tables for Negation, Conjunction, and Disjunction
Section 6.1 Order of Operations
Lesson 1 – 5 Solving Inequalities.
Section 6.1 Order of Operations
LINEAR EQUATIONS.
Do Now Simplify. 1. 5(7) – (18 – 11)  (40 – 35) (12 – 4)
Solving Equations with Variables on Both Sides Day 2
STATE STANDARDS S.P.I Apply properties to evaluate expressions, simplify expressions, and justify solutions to problems. S.P.I Write.
Presentation transcript:

Compound Conditionals Ball State University - CS4MS - Fall 2018

What is a boolean? A variable that has 2 possible values (True or False) A boolean is a name for something that can only be True or False To fully understand what conditional statements are, you first need to know what a boolean is.

What is a conditional statement? Tells a program to do different actions depending on whether a boolean condition is true or false. These are usually “if” statements. Manipulate the control flow of a program. The control flow is the order that instructions run in a program.

Symbols used in conditionals... == means “equal to” || means “or” && means “and” Anything inside ( ) is grouped ! means “not” != means “not equal to” > means “greater than” < means “less than”

Truth Table for AND The symbols && stands for the AND operator. Condition 1 AND True False TRUE FALSE Condition 2

Truth Table for OR The symbols || stands for the OR operator. Condition 1 OR True False TRUE FALSE Condition 2

Truth Table for NOT The symbol ! stands for the NOT operator. NOT Condition 1 True False FALSE TRUE The NOT operator switches a condition or boolean statement to its OPPOSITE.

Steps to solve conditional statements: Pay attention to the order of operations. Simplify expressions inside parentheses first. Then apply operations outside parentheses. NOTE: String variables are formatted inside quotation marks, and need to match exactly for an == expression to evaluate to true. NOTE: Var stands for variable (which acts as a “placeholder” for a known or unknown entity).

Example 1 Two variables, month and day, have been initialized with the values shown below: var month = “January”; var day = 26; Does the following conditional statement evaluate to True or False? (month == “January”) && (day == 25)

Example 1 (Solution - Step 1) Two variables, month and day, have been initialized with the values shown below: var month = “January”; var day = 26; Does the following conditional statement evaluate to True or False? (month == “January”) && (day == 25) Begin by looking at the expression within the first parentheses: (month == “January”) The == symbol means “equal to”, and since the variable month was initialized to “January”, this expression is TRUE.

Example 1 (Solution - Step 2) Two variables, month and day, have been initialized with the values shown below: var month = “January”; var day = 26; Does the following conditional statement evaluate to True or False? (month == “January”) && (day == 25) Now, we are left with the following: TRUE && (day == 25) Next, simplify the expression in the remaining parentheses. Since the variable day was initialized to 26 (and NOT 25), this statement is FALSE.

Example 1 (Solution - Step 3) Two variables, month and day, have been initialized with the values shown below: var month = “January”; var day = 26; Does the following conditional statement evaluate to True or False? (month == “January”) && (day == 25) Now, we are left with the following statement: TRUE && FALSE The && symbol means “and”. For an “and” expression to be true, BOTH statements need to be true. Therefore, the above statement is FALSE! Our final answer is FALSE.

Example 2 Two variables, count and name, have been initialized with the values shown below: var name = “Jacob”; var count = 7; Does the following conditional statement evaluate to True or False? ((count > 7) || ((count + 3) < 15))

Example 2 (Solution - Step 1) Two variables, count and name, have been initialized with the values shown below: var name = “Jacob”; var count = 7; Does the following conditional statement evaluate to True or False? ((count > 7) || ((count + 3) < 15)) Begin by looking at the expression within the first parentheses inside the outer parentheses: (count > 7) The > symbol means “greater than”, and since the variable count was initialized to 7, this expression is FALSE because 7 is not greater than 7. They are equal.

Example 2 (Solution - Step 2) Two variables, count and name, have been initialized with the values shown below: var name = “Jacob”; var count = 7; Does the following conditional statement evaluate to True or False? ((count > 7) || ((count + 3) < 15)) Now, we are left with the following: ((FALSE) || ((count + 3) < 15)) Next, simplify the expression in the second inner set of parentheses: ((count + 3) < 15)) Since the variable count was initialized to 7, 7 + 3 equals 10 which is indeed less than 15, so this statement is TRUE.

Example 2 (Solution - Step 3) Two variables, count and name, have been initialized with the values shown below: var name = “Jacob”; var count = 7; Does the following conditional statement evaluate to True or False? ((count > 7) || ((count + 3) < 15)) Now, we are left with the following: FALSE || TRUE Using the truth table for OR, we can simplify this expression to TRUE. Our final answer is TRUE.