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 |
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
- Operator precedence
- Parentheses
- Arithmetic expression evaluation
- Control statements
- Sequential execution
- Conditional execution
ifstatementif...elsestatement- Comparison and logical operators in conditions
- Indentation
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
- Variables
- Basic Python syntax
- Arithmetic operators
- Comparison operators
- Logical operators
print()andinput()
Likely Misconceptions
- Python evaluates every operator from left to right without rules.
=and==mean the same thing.- An
ifstatement always requires anelse. - Indentation is only for visual appearance.
- The condition itself produces output automatically.
- Parentheses are unnecessary when an expression contains several operators.
3. Learning Objectives
By the end of the session, students will be able to:
- Explain the meaning of operator precedence.
- Use parentheses to control the order of evaluation.
- Predict the result of simple Python expressions.
- Explain the purpose of control statements.
- Differentiate between sequential and conditional execution.
- Write simple
ifstatements. - Write simple
if...elsestatements. - Use comparison and logical operators in conditions.
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
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 |
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. |
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.")
: 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")
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
- What is operator precedence?
- Which is evaluated first:
10 + 5 * 2? - Why are parentheses useful?
- What is a control statement?
- What is a conditional statement?
- What is the difference between
ifandif...else? - Why is indentation important in Python?
- What is the difference between
=and==?
22. Homework
-
Evaluate and write the output of:
20 + 5 * 2. -
Evaluate:
(20 + 5) * 2. - Write a program to check whether a number is positive or negative.
- Write a program to check whether a student has passed or failed.
- 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
- Could students explain operator precedence in their own words?
- Could students correctly predict expression outputs?
- Could students distinguish sequential and conditional execution?
- Could students write a syntactically correct
ifstatement? - Did students use
==correctly for comparison? - Did students understand the importance of indentation?
- Which students require additional practice with conditions?