1 of 17

Lesson 11 : Boolean Operator

Challenge focus: 75 - 78

Coding Concepts : not operator

Properties

  • mouth_closed

Methods

  • toggle()

.

December 2023

Banana Tales I

Key stage III

Class VII

2 of 17

LESSON OVERVIEW

CODING CONCEPT

Boolean Operators (not)

CHALLENGE

75

76

77

78

SUB CONCEPTS

  • The importance of the boolean operator(not).
  • Truth table of the not operator.
  • not operator with the if/if-else statement.

RESOURCES

December 2023

Banana Tales I

Key stage III

Class VII

3 of 17

Lesson Objectives

At the end of the lesson, each child should be able to:

  • The importance of the boolean operator(not).
  • Truth table of the not operator.
  • not operator with the if/if-else statement.
  • Complete challenges 75 - 78.

December 2023

Banana Tales I

Key stage III

Class VII

4 of 17

Understanding not Operator

  • The not operator reverses the result of the condition: True becomes False, and False becomes True.
  • The not operator can be used in a conditional loop (while loop) or in an if statement.
  • Truth Table:

Condition

not condition

True

False

False

True

December 2023

Banana Tales I

Key stage III

Class VII

5 of 17

Activity 1

Study the given statements and state whether it is true or false.

X

Y

X or Y

X and Y

not (X and Y)

75 != 10

80 >= 100

67 <= 89

90 > 35

89 == 89

200 < 300

December 2023

Banana Tales I

Key stage III

Class VII

6 of 17

Activity 1 Solution

X

Y

X or Y

X and Y

not (X and Y)

75 != 10

80 >= 100

True or False = True

True and False = False

True

67 <= 89

90 > 35

True or True = True

True and True = True

False

89 == 87

200 < 150

False or False = False

False and False = False

True

December 2023

Banana Tales I

Key stage III

Class VII

7 of 17

Demo 1

Study the challenge carefully. Write the codes in your notebook to help the banana reach to the monkey (challenge 75).

December 2023

Banana Tales I

Key stage III

Class VII

8 of 17

Demo 1 Solution

1

2

3

4

if not well.crocodile.mouth_closed:

well.crocodile.toggle()

while well.water_level < well.max_water_level:

elephant.spray_at(well)

condition

  • The ‘if’ statement along with ‘not’ operator will help in closing the mouth of crocodiles.
  • The while loop will help in filling up the wells with water.
  • mouth_closed: The property of a crocodile object.
  • toggle(): This method switches between the two states of the crocodile's mouth - open and closed.

operator

December 2023

Banana Tales I

Key stage III

Class VII

9 of 17

Activity 2

Study the following challenge and solution carefully. Then answer the following questions in your notebook (challenge 77).

December 2023

Banana Tales I

Key stage III

Class VII

10 of 17

Activity 2 (Cont.)

  1. Why is a for loop used in Line 1?
  2. What does the len() function used in Line 1 do?
  3. What does the if statement in Line 2-3 do?
  4. What does the while loop in Line 6-7 do?

December 2023

Banana Tales I

Key stage III

Class VII

11 of 17

Activity 2 Solution

  • Why is a for loop used in Line 1?

Ans: A for loop is used because there are many wells to fill up with water and many crocodiles to close mouth.

  • What does the len() function used in Line 1 do?

Ans: The len() function used as len(wells) in Line 1 will count the total number of wells in the list called wells.

  • What does the if statement in Line 2-3 do?

Ans: The if statement in Line 2-3 will check whether a crocodile’s mouth is opened or not. If it is open, then the state is toggled.

  • What does the while loop in Line 6-7 do?

Ans: The while loop in Line 6-7 will make the elephants spray water in their respective wells until the current water_level of the wells become equal to its max_water_level.

December 2023

Banana Tales I

Key stage III

Class VII

12 of 17

Activity 3 - Practical

  • Log into your CodeMonkey account.
  • Open Banana Tales Part I
  • Complete challenges 75 to 78.

December 2023

Banana Tales I

Key stage III

Class VII

13 of 17

Activity 3 Solution

75

December 2023

Banana Tales I

Key stage III

Class VII

14 of 17

Activity 3 Solution

76

December 2023

Banana Tales I

Key stage III

Class VII

15 of 17

Activity 3 Solution

77

December 2023

Banana Tales I

Key stage III

Class VII

16 of 17

Activity 3 Solution

78

December 2023

Banana Tales I

Key stage III

Class VII

17 of 17

Key Points

  • The not operator reverses the result of the condition: True becomes False, and False becomes True.
  • The not operator can be used in a conditional loop (while loop) or in an if statement.
  • Crocodile object has a property called mouth_closed which determines its mouth state.
  • The method toggle() switches between the two states of the crocodile's mouth - open and closed.

December 2023

Banana Tales I

Key stage III

Class VII