TN Online TestSamacheer Kalvi practice

Control Structures - Study Notes

Share this chapter: Telegram

Chapter Summary

Python programs execute sequentially by default, but control structures allow developers to alter this path through decision-making branches and loops. This chapter details branching methods such as simple if, if-else, and nested if-elif-else structures, iterative patterns like while and for loops, and jump statements like break, continue, and pass.

Learning Objectives

Key Concepts and Definitions

Worked Methods

Finding the Smallest of Three Numbers

We use a nested conditional structure to evaluate and compare three distinct numerical inputs pairwise, assigning the minimum value to a variable.

num1, num2, num3 = 12, 5, 8
if num1 <= num2 and num1 <= num3:
    smallest = num1
elif num2 <= num1 and num2 <= num3:
    smallest = num2
else:
    smallest = num3

Generating Steps with the range() Function

To print all even numbers between 2 and 20 (inclusive), the range function is called with a step value of 2 inside an iterative loop.

for i in range(2, 21, 2):
    print(i)

Common Exam Traps

Exam Tips

Solved MCQs → Practice test →

More for this chapter

Book Back Questions10 textbook MCQs · solved Additional MCQs15 extra MCQs · solved Practice TestInteractive · instant score Book Back TestTest yourself on the textbook set Additional MCQ TestTest yourself on the extra set Formula SheetAll key formulas

More chapters in Computer Science

View all
1 Function 2 Data Abstraction 3 Scoping 4 Algorithmic Strategies 5 Python -Variables and Operators 7 Python functions 8 Strings and String manipulation 9 Lists, Tuples, Sets and Dictionary 10 Python Classes and objects 11 Database Concepts 12 Structured Query Language (SQL) 13 Python and CSV files 14 Importing C++ programs in Python. 15 Data manipulation through SQL 16 Data visualization using pyplot: line chart, pie chart and bar chart