Download presentation
Presentation is loading. Please wait.
Published byMercedes Rubio Silva Modified over 5 years ago
1
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
DeMorgan’s Laws Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
2
Opposites Sometimes we need to find the opposites of conditions
An example is error checking to prompt the user for the correct value We know what kind of value we want But we have to loop on a condition for the values we don’t want… Other examples, too
3
Thought Puzzle What is the opposite of:
if small<middle and middle<large : A: if small<middle or middle<large : B: if small>=middle and middle>=large : C: if small>=middle or middle>=large :
4
Thought Puzzle What is the opposite of:
if small<middle and middle<large : For that whole statement to be true, both (small < middle) == true and (middle < large) == true
5
Thought Puzzle What is the opposite of:
if small<middle and middle<large : For that whole statement to be false, at least (first statement) == false or (second statement) == false
6
Thought Puzzle What is the opposite of:
if small<middle and middle<large : For that whole statement to be false, at least not(small<middle) or not(middle<large)
7
Thought Puzzle What is the opposite of:
if small<middle and middle<large : For that whole statement to be false, at least (small>=middle) == false or (middle>=large) == false
8
DeMorgan’s Laws The opposite of: A and B Is opposite (A and B) = opposite(A) or opposite(B)
9
So how do you go the other way?
The opposite of: A or B Is opposite (A or B) = opposite(A) and opposite(B)
10
In-Class Activities Say you only accept a positive integer between 1 and 10 (inclusive) What is the opposite of: If val >=1 and val <=10
11
In-Class Activities Say you only accept the input strings “yes” and “no” What is the opposite of If val==“yes” or val==“no”
12
In-Class Activities Remember the Latin Squares?
order number must be positive startingNumber between 1 and order (inclusive) What is the opposite of: if order > 0 and (0 < startingNumber >= order)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.