Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg

Slides:



Advertisements
Similar presentations
Lesson 6: Boolean and If Statements Computer Science 1 Mr. Bernstein.
Advertisements

Computer Science 101 While Statement. Iteration: The While-Statement The syntax for the While- Statement is while : The syntax for the While- Statement.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
CS150 Introduction to Computer Science 1
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
COM S 207 While-Loop Statement Instructor: Ying Cai Department of Computer Science Iowa State University
Introduction to Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Lab 07: Caesar Cypher Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Algorithms and DeMorgan’s Laws Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Advanced Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Section 6.4 Factoring Special Forms. 6.4 Lecture Guide: Factoring Special Forms Objective 1: Factor perfect square trinomials.
TOPIC 8 MORE ON WHILE LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
CS 1430: Programming in C++ No time to cover HiC.
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
CS 115 Lecture Flags.
CS161 Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Thinking about programming
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
Introduction to Strings
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
More Nested Loops and Lab 5
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Intro to Nested Looping
String Encodings and Penny Math
Unary Operators ++ and --
CS 115 Lecture Flags.
Binary Search and Intro to Sorting
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Thinking about Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Nested Looping
Algorithms and DeMorgan’s Laws
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Introduction to Strings
More Repetition While and For loop variations
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Thinking about programming
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Computer Science
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Introduction to Strings
Intro to Nested Looping
String Encodings and Penny Math
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Types, Truth, and Expressions
Introduction to Strings
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Presentation transcript:

Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg DeMorgan’s Laws Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg

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

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 :

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

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

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)

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

DeMorgan’s Laws The opposite of: A and B Is opposite (A and B) = opposite(A) or opposite(B)

So how do you go the other way? The opposite of: A or B Is opposite (A or B) = opposite(A) and opposite(B)

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

In-Class Activities Say you only accept the input strings “yes” and “no” What is the opposite of If val==“yes” or val==“no”

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)