Decision Structures Chapter 4 Part 2. Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing.

Slides:



Advertisements
Similar presentations
Example: Multiple Conditions Execution Control with If Else and Boolean Questions Alice.
Advertisements

Class-level Methods Chapter 6. Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class.
Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
Decision Structures Chapter 4. Chapter 4 Objectives To understand: o What values can be stored in a Boolean variable o What sequence structures are and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Events Chapter 7. Interactivity The real world is interactive User determines order of actions instead of programmer.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Repetition Structures
Programming: Simple Control Structures Part 1 – Conditional Execution Alice.
Functions and Visual Effects Chapter 6 Part 3. Built-in Functions We have been using built-in functions so far 2.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Creating Functions Deborah Nelson Duke University Professor Susan Rodger July 22, 2008.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Branching and Looping Examples, cont’d. Remember the generic triple jump world…
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.
Decision Structures and Boolean Logic
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Execution Control with If/Else and Boolean Functions Alice.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
© Jalal Kawash Programming Peeking into Computer Science 1.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
© The McGraw-Hill Companies, 2006 Chapter 2 Selection.
Mathematical Expressions, Conditional Statements, Control Structures
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Programming: Putting Together the Pieces Built-in Questions and Expressions Alice.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Repetition Structures Chapter 5 Part The While Instruction  Combines Loop and the condition that is also used in If/else statements  The loop.
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Programming: Simple Control Structures Sec 46 Web Design.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
More on the Selection Structure
Programming: Putting Together the Pieces Built-in Functions and Expressions Sec 8-5 Web Design.
Programming: Simple Control Structures
Chapter 3: Decisions and Loops
Programming: Simple Control Structures
Simple Control Structures
Introduction To Robot Decision Making
Programming: Simple Control Structures
CS320n –Visual Programming
Programming: Simple Control Structures
Control Structures: Selection Statement
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Simple Control Structures
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Introduction To Robot Decision Making
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Conditional Logic Presentation Name Course Name
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Programming: Simple Control Structures
Relational Expressions
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Programming: Simple Control Structures
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Execution Control with If/Else and Boolean Questions Example: Multiple Conditions Alice.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Presentation transcript:

Decision Structures Chapter 4 Part 2

Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing the value of an object’s property 4-2

Relational Comparisons  Relational Operators are used to compare values and determine whether relationships exist o Greater than o Less than o Equal to  Compare two values and determine how they relate to each other OperatorMeaning = Equal to ! =Not equal to >Greater than > =Greater than or equal to <Less than < =Less than or equal to 4-3

Relational Operators  Used to write your own comparison o In If/Else and other tests  Operates on two pieces of data o a and b  Alice uses “a” and “b” for placeholders o Drag the desired tile and replace either the “a” or “b” with a value 4-4

Concept Illustrated Relational operations are defined using relational operators 4-5

Boolean Logic Can check for multiple conditions at one time with Boolean logic instead of nesting If/else statements Boolean logic operators are used to build an expression composed of multiple conditions o And  Boolean: A and B: True only when both are true  In Alice: Both A and B o Or  Boolean: A or B: True when one or both are true  In Alice: Either A or B, or both o Not  Inverses what is sent to it Example: if A = True then not A is False  In Alice: not A 4-6

Boolean Logic in Functions Choose World object Then choose functions o Select desired Boolean function o Drag to conditional instruction like If/Else Condition 4-7

Logical Operators Tests more than true/false Can do complex testing Test two conditions to see if o They BOTH are true (and) o ONLY one condition is true (or) o NEITHER condition is true (not) 4-8

Example Can combine multiple conditions Example: Condition is true if o The penguin is within 2 meters o And the circle is wider than the penguin Similar to nested If/Else but doesn’t do contents of second Else statement o Penquin says “Drats“ 4-9

Testing Value of Object’s Property Sometimes you might want to see what a property of an object is o Color o Opacity o isShowing 4-10

How to Testing Object’s Property Create an empty If/Else instruction Select object to test Click properties tab Drag desired property’s tile and drop onto If/Else instruction’s condition Menu appears showing all comparisons to perform o Select desired comparison Another menu appears allowing you to select value that you want to compare property to o Ex: color property will give list of colors 4-11

Example Algorithm Frog and ladybug are in garden 4-12 Ladybug says “Excuse me” Frog turns to face ladybug If ladybug’s color is red Frog says “EEK! Go away!” Else Frog says “Good Morning” Endif

Property Test Demonstration 4-13

Homework Read chapter 4.4 Do lab assignments Answer questions in handout Due one week after assigned with 1 week grace 4-14