Skip to contentSkip to navigation

Module 2

Operators and Control Flow

Master Python operators, user input, smart decision branching, and powerful loops.

// Lessons

6

// Quiz questions

90

// Reading time

90 min

// Exam length

15 Q

// Coding exercises

10

  1. 1Operators & ExpressionsPerform calculations, evaluate comparisons, and check identity or membership across expressions. 15 min 15 questions
  2. 2Operator Precedence & EvaluationMaster PEMDAS execution order, short-circuit boolean logic, and truthy versus falsy evaluations. 15 min 15 questions
  3. 3Interactive Input & OutputCapture user terminal inputs, format dynamic strings with f-strings, and handle stream I/O. 15 min 15 questions
  4. 4Conditional Branching (if / elif / else)Control decision branches, chain relational comparisons, and evaluate multi-condition logic. 15 min 15 questions
  5. 5Definite Iteration & for LoopsTraverse sequences and collections, generate indices with range(), and accumulate running values. 15 min 15 questions
  6. 6Indefinite Loops & Loop ControlManage condition-driven repetition with while loops, short-circuit with break, and advance with continue. 15 min 15 questions

Coding practice: write it yourself

Real Python, real checks: write your answer, press Run checks, and keep going until it passes. (4 exercises)

All module exercises

Coding practice needs an account. Sign in or create a free ID to run these exercises.

Lab 1: Even or odd?

Sign-in required

number = 8. Print EVEN if it divides by 2 with no remainder, otherwise ODD.

Coding Practice is Locked

Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.

Lab 2: Times table rows

Sign-in required

Using a for loop over range(1, 4), print:

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15

Coding Practice is Locked

Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.

Lab 3: Pass mark check

Sign-in required

Bangladesh's pass mark is 33. For marks = 38, print PASS when marks is at least 33, else FAIL.

Coding Practice is Locked

Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.

Lab 4: Exam countdown

Sign-in required

Print a countdown from 3 down to 1, one number per line, using a while loop.

Coding Practice is Locked

Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.

References & Further Reading

Related entries from PyLabs's own reference library.

  • bool() (Convert a value to True or False.)
  • range() (Make a sequence of evenly spaced integers.)
  • enumerate() (Pair each item with a counter.)