Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations

Presentation on theme: "Lesson 6: Boolean and If Statements Computer Science 1 Mr. Bernstein."— Presentation transcript:

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

2 BOOlean Boolean are statements that yield a truth or false value. Works with Strings and Integers

3 BOOlean Expressions Examples: a == b (== not initiating variables) 2 == 3 a > b a < b 10 >= 10 5 != 2

4 True or False True or True = True or False = False or True = False or False =

5 True or False True and True = True and False = False and True = False and False =

6 NOT! not False = not (True or False) = not (False and False) = not (True or True) =

7 DeMorgans Law not (P and Q) = not P or not Q For example: not (True and False) = not True or not False

8 If Conditional Statements if RELATIONALEXPRESSION: statement Lowercase if Colon after the RE Statements that follow must be indented

9 If Example: if rg3 == injured: print(RG3 is out for the season!) if rg3 != quarterback: print(RG3 is not the quarterback!)

10 IF Examples: rgcondition = good condition qb = rg3 if rgcondition == injured: print(RG3 is not playing next Sunday.) if rgcondition != injured and qb == rg3: print(RG3 is playing this Sunday!)

11 All together! Write a program that prompts the user how many hours they work. (input) If they work 40 hours or less, they make 8 dollars an hour. (if statement) If they work more than 40 hours, each hour after they make 10 dollars an hour. (if statement) Determine how much a person makes if they work: 21 hours, 40 hours, 48 hours

12 Else and elif Statement No need for multiple if statements! if ( apple > 10): print(I has more apples!) elif (apple <= 10): print(I has less apples :-( ) else: print(I dont know how many I have!)

13 Example in Class Write me a program that tells me what is for lunch when the user inputs a day of the week. (prompt the user) Monday – Sloppy Joes Wednesday – Chicken Patties Friday - Salads Tues/Thurs – Pizza (challenge) What if someone inputs Sat/Sun? What if they dont input a day of the week?

14 Summary Boolean – True or False If statement –RelationalExpression: (colon) statement If, Elif, and Else – Conditions that arent easily put into an if statement

Download ppt "Lesson 6: Boolean and If Statements Computer Science 1 Mr. Bernstein."

Similar presentations

Ads by Google