Stage 1 · Lesson 3 of 9
Conditionals and loops
(if, elif and else) let a program choose between paths, and let it repeat work. Use a for loop to walk over anything you can step through, such as the letters of a word (for ch in word) or a range of numbers. for i in range(5) gives 0 to 4, not 1 to 5.
Use a while loop when you do not know the count in advance, such as asking again until the input is valid. Make sure something inside it changes the condition, or it never ends. break leaves a loop early and continue skips to the next pass.
Python also treats empty strings, 0, and empty lists as false. These are called . They keep conditions short, but they hide bugs when 0 is a valid value. Trace small loops on paper until the counts feel obvious.
A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Python Fundamentals
Design Gurus · Beginner · $50
Beginner Python with an in-browser exercise after nearly every lesson
- CourseFreeCS50's Introduction to Programming with Python
Harvard University · Beginner
Free Harvard course whose weekly problem sets make you write real programs