Skip to Content
Course content

Control Flow: if/elif/else, loops

Control the path your program takes: branch on conditions and repeat work without repeating code.

Key topics

  • if / elif / else; nested conditions; ternary expressions.
  • for loops over ranges, strings and collections; range(), enumerate(), zip().
  • while loops and sentinel values; avoiding infinite loops.
  • Loop control: break, continue, else on loops.
  • List and dictionary comprehensions; when they help and when they hurt readability.

Exercise / deliverable

Write a number-classifier script: for numbers 1–50 print "Fizz" (÷3), "Buzz" (÷5), "FizzBuzz" (both) or the number, then count and display how many of each category were printed using a loop — no hard-coded counts.

Level: Beginner | Duration: ~0.5h. Decision-making and repetition: conditionals, for/while loops, break/continue and comprehensions.
Rating
0 0

There are no comments for now.