Grade VII Computer Science

Chapter 7: More on Python

Session 2: Operator Precedence, Control Statements & Conditional Statements

1. Session Overview

Class VII
Subject Computer Science
Chapter Chapter 7: More on Python
Session 2
Topic Operator Precedence; Control Statements; Conditional Statements
Suggested Duration 40–45 minutes
Session Focus: Students learn how Python evaluates expressions and how conditional statements allow a program to make decisions based on conditions.

2. Research Record

Curriculum Research

This session builds on the previous study of Python operators. Students now learn how Python determines the order in which operators are evaluated and how control statements change the flow of program execution.

Content Research

Learner Research

Grade VII students can understand conditional programming most effectively when programming decisions are connected with familiar situations such as marks, age, weather, numbers and eligibility.

Prerequisites

Likely Misconceptions

3. Learning Objectives

By the end of the session, students will be able to:

4. Operator Precedence

Operator precedence determines the order in which operators are evaluated in an expression.

For example:

result = 10 + 5 * 2

Multiplication is performed before addition, so the result is:

20
Remember: When operators have different precedence levels, the operator with higher precedence is evaluated first.

5. Common Python Operator Precedence

Priority Operator / Expression Example
Highest Parentheses () (5 + 2) * 3
High Exponentiation ** 2 ** 3
Medium * / // % 10 * 2
Lower + - 10 + 2
Lower Comparison operators 10 > 5
Lower not not True
Lower and True and False
Lowest among these or True or False
For Grade VII, students should focus primarily on understanding the practical idea of "which operation happens first" rather than memorising the complete Python precedence table.

6. Using Parentheses

Compare:

result1 = 10 + 5 * 2
result2 = (10 + 5) * 2

print(result1)
print(result2)

Output:

20
30

Parentheses force the expression inside them to be evaluated before the multiplication.

7. Control Statements

Normally, Python executes statements from top to bottom. Control statements allow a programmer to influence the order or conditions under which statements execute.

Type Purpose
Sequential Executes statements one after another.
Conditional Executes statements depending on a condition.
Iterative Repeats statements.
In this session: The focus is on conditional control.

8. Sequential Execution

In sequential execution, Python executes statements in the order in which they are written.

name = "Riya"
age = 12

print(name)
print(age)

The first statement executes first, followed by the second and then the print() statements.

9. Conditional Statements

A conditional statement allows a program to make a decision based on whether a condition is True or False.

Example:

marks = 75

if marks >= 40:
    print("Pass")

Since 75 >= 40 is True, the message is displayed.

10. The if Statement

Syntax:

if condition:
    statement

Example:

age = 18

if age >= 18:
    print("You are eligible.")
Important: Notice the colon : after the condition and the indentation before the statement.

11. The if...else Statement

The if...else statement provides two possible paths. One block executes when the condition is True, and the other executes when it is False.

marks = int(input("Enter marks: "))

if marks >= 40:
    print("Pass")
else:
    print("Fail")

12. Conditions and Comparison Operators

Comparison operators are commonly used to create conditions.

Operator Meaning
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

13. Using Logical Operators in Conditions

Logical operators can combine more than one condition.

age = 15

if age >= 13 and age <= 19:
    print("Teenager")

Here, both conditions must be True for the message to be displayed.

14. Practical Examples

Example 1: Positive Number

number = int(input("Enter a number: "))

if number > 0:
    print("Positive number")

Example 2: Even or Odd

number = int(input("Enter a number: "))

if number % 2 == 0:
    print("Even")
else:
    print("Odd")

Example 3: Temperature

temperature = float(input("Enter temperature: "))

if temperature > 35:
    print("It is hot.")
else:
    print("It is not very hot.")

15. Teaching Strategy

Stage Teacher Action Student Action
Recall Review operators. Identify operators.
Engage Present everyday decision-making examples. Explain how decisions are made.
Explain Introduce precedence and control flow. Predict outcomes.
Demonstrate Write if and if...else programs. Trace the programs.
Guided Practice Provide simple decision problems. Write programs with assistance.
Independent Practice Provide a programming challenge. Write and test the program.

16. Classroom Activity

Activity: Computer Decision Maker

Ask students to think of decisions they make every day.

Examples:

  • If it rains → carry an umbrella.
  • If marks are 40 or above → pass.
  • If a number is even → divide it by 2.

Students then convert one of these decisions into a Python if or if...else statement.

17. Computer Lab Activity

Task 1: Pass or Fail

Accept marks and display Pass if marks are 40 or above; otherwise display Fail.

Task 2: Even or Odd

Accept a number and determine whether it is even or odd.

Task 3: Greater Number

Accept two numbers and display which number is greater.

Task 4: Eligibility

Accept the user's age and display whether the person is eligible to vote under the age criterion of 18 years.

18. Predict the Output

Question 1

print(10 + 5 * 2)

Question 2

print((10 + 5) * 2)

Question 3

x = 8

if x > 5:
    print("A")
else:
    print("B")

Question 4

x = 3

if x > 5:
    print("A")
else:
    print("B")

19. Debug the Program

Find and correct the error:

marks = 70

if marks >= 40
    print("Pass")
else:
    print("Fail")
Hint: Check the punctuation immediately after the condition.

20. Assessment

Assessment Method Evidence of Learning
Oral Questioning Operator precedence and control statements.
Output Prediction Students determine expression and conditional outputs.
Worksheet Identify conditions and correct errors.
Practical Observation Write, execute and debug conditional programs.

21. Quick Check

  1. What is operator precedence?
  2. Which is evaluated first: 10 + 5 * 2?
  3. Why are parentheses useful?
  4. What is a control statement?
  5. What is a conditional statement?
  6. What is the difference between if and if...else?
  7. Why is indentation important in Python?
  8. What is the difference between = and ==?

22. Homework

  1. Evaluate and write the output of: 20 + 5 * 2.
  2. Evaluate: (20 + 5) * 2.
  3. Write a program to check whether a number is positive or negative.
  4. Write a program to check whether a student has passed or failed.
  5. Write a program to check whether a number is divisible by 5.

23. Extension Challenge 🚀

Simple Grade Calculator

Write a program that accepts marks and displays:

  • A for marks 80 or above
  • B for marks 60–79
  • C for marks 40–59
  • Needs Improvement below 40

Challenge: Try solving this using multiple conditional branches.

24. Summary

In this session, students learned that operator precedence determines the order in which Python evaluates expressions. They also learned that control statements influence the flow of program execution.

Students then explored conditional statements, particularly if and if...else, and used comparison and logical operators to make Python programs respond differently to different conditions.

25. Teacher Reflection