Download presentation
Presentation is loading. Please wait.
Published byAmy Leonard Modified over 8 years ago
1
Intro CS – Logic & Operators Lesson Plan 5
2
Goals Students can explain basic logical operators AND, OR, NOT Students can create truth tables for the operators Students can explain when logic operators are needed Students can choose appropriate logic operators for a situation Students can evaluate given logic expressions Students can write logic expressions
3
Objectives Students are introduced to logic operators to combine tests, typically used in IF statements Students are given real problems to code and solve using IF blocks and logic operators Results are demonstrated through demos of running code and displayed results
4
Pre Requisites Knowledge of IF blocks Basic Understanding of BYOB
5
Materials Slides with examples (or present on whiteboard) PCs with development environments installed
6
Lesson Description Students learn to define basic logic operators Students apply the logic operators to given problems Students practice and extend examples Students present their solutions, typically F2F with the instructor(s) at their desk Students analyze their and others’ solutions for bugs
7
Lesson Procedure Quick review of IF blocks Introduce logic operators through student investigation Give exercises for in class practice Walk the room answering questions, looking over the shoulder, asking questions, etc. Review
8
Closure/Conclusion Summary IF blocks help you make decisions, and take action if TRUE Logic operators can be added anywhere a true/false test is used (If, If/Else, Repeat until, Wait until) Ask questions on what is confusing or needs more time/practice
9
Logic Operators Lesson Plan 5
10
Review: IF blocks What are IF Blocks? IF blocks are used to help make decisions and branch your code. When the IF Block statement is true, whatever is contained inside the decision block is done Other blocks that use logic: IF/ELSE, Repeat Until, Wait Until
11
Combining Logic 0 Sometimes we need to take multiple pieces of information in, and make decisions 0 This information can be combined in many ways 0 Examples: 0 If I get my homework done, AND I walk the dog, OR my Mom’s NOT home, THEN I can play video games after school 0 If I play video games before my homework is done AND before I walk the dog, AND my Mom comes home, THEN I can’t play video games for a week
12
Investigation 0 Pair up. If you get stuck, ask another pair. 0 Investigate and write down on paper or in online notes: 0 Define and explain AND, OR, NOT as they relate to programming/computer science 0 What is a Truth Table? 0 Find and recreate the truth tables for AND, OR, NOT 0 Write a combined logic example using AND, OR, and NOT (all in one IF statement) using Snap
13
When to use 0 AND 0 When both things tested are true, then do something 0 Who can give an example from a project we’ve done? 0 OR 0 When either thing tested is true, then do something 0 Who can give an example from a project we’ve done 0 NOT 0 Take the opposite of whatever is being tested 0 Who can give an example from a project we’ve done
14
Example Cheese Puff Girl, version 2.0 If Cheese Puff Girl is touching the Cheetos, AND the mouse is down OR the Space key is pressed AND the variable OnStartScreen is NOT true, THEN Hide/respawn the Cheetos Bump the score by one
15
Practice Evaluating 0 (1 4)=? 0 Count=3 NOT (Count>3)=? 0 X position = 100, Y position = 50 ((X>90) AND (X 90) AND (X 40))=?
16
Practice creating 0 Write an expression to determine the following: 0 Whether the X position of a sprite is bigger than 200 0 Whether a variable INPUT is not between 5 and 10 0 Whether two variables, X and Y, are not equal to each other 0 Whether at least $1.25 has been added to the machine, and the person has pressed the button for Snapple Lemon Tea
17
Practice 0 Which value for x will make the statement below true? ( x > 0 ) AND ( x < 4 ) 0 Which value for x will make the statement below true? ( x > 0 ) OR ( x < 0 )
18
Tough Practice 0 Which truth table represents the statement:
19
Congrats 0 You’ve just learned the basics of Boolean algebra (but there’s much more to learn in advanced classes) 0 Boolean means True/False, On/Off, etc. 0 We can combine tests for True/False with AND/OR/NOT 0 Truth tables show us the output for given inputs
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.