Week 4 - Decisions

# and is your number greater than 5 and less than 10

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: pressions Is this ball red AND round? Is this ball red AND round? 17 Pick a number between 1 and 10... •  AND –  Both must be true –  Example: •  Is your number greater than 5 AND less than 10? •  OR –  Either may be true –  Example: •  Is your number 5 OR 10? 18 Syntax: and or •  AND (expression1) && (expression2) –  Both expression1 AND expression2 must be true for the whole to be true •  OR (expression1) || (expression2) –  Either expression1 OR expression2 may be true for the whole to be true 19 Pick a number between 1 and 10... •  AND –  Is your number greater than 5 AND less than 10? (number > 5) && (number < 10) •  OR –  Is your number 5 OR 10? (number == 5) || (number == 10) 20 Lets write some expressions… Pick a number between 1 and 10… •  Is your number between 3 and 7? •  Is your number smaller than 5? •  Is your number odd? 21 Lets write some expressions… Pick a number between 1 and 10… •  Is your number between 3 and 7? (number > 3) && (number < 7) •  Is your number smaller than 5? number < 5 •  Is your number odd? (number % 2) != 0 22 Syntax: not •  A boolean expression can be negated using the "not" (!) operator •  Syntax !(condition) •  Examples !(num >= 0) (a || b) && !(a && b) 23 How to avoid using not What is the equivalent expression of the following: •  !(number < 5) •  !(number >...
View Full Document

## This note was uploaded on 02/17/2014 for the course ITP 109 taught by Professor Trinagregory during the Spring '12 term at USC.

Ask a homework question - tutors are online