Example
For Loop Basics
For loop iterates through sequence elements. Basic iteration over lists.
Showing 1–10 of 57
Example
For loop iterates through sequence elements. Basic iteration over lists.
Quiz
Free beginner quiz on Python for loops: 15 questions on lists, strings, range(), enumerate(), totals and break, with instant answers.
Example
Functions enumerate() and range() extend for loop capabilities in Python.
Quiz
Free beginner quiz on Python while loops: 15 questions on conditions, counters, infinite loops, break and continue, with instant answers.
Challenge
A loop over range(1, 10) logs nine orbits of a ten-orbit flight. Predict the last line, find out where range() stops, fix it with ORBITS + 1, then list every third orbit with a range() step.
Challenge
…ERROR Fuel valve 2 still closed Start with alerts = [] , loop over the log, and append() each line that contains "] WARN" or "] ERROR" . The log itself must stay complete. A minimum level Make the…
Challenge
Extend the OK/WARN/CRITICAL check from Alert level so a for loop runs it over every temperature in a list, then count the WARN and CRITICAL readings for a summary line.
Challenge
Scan the mission log for the first ERROR entry, print its line number with enumerate() and stop there with break, then report how many lines were checked, or that there were no errors at all.
Challenge
Print one cargo manifest line for every record in a list of dicts, reading each field by key, then add up the masses in the same loop for a total line.
Example
Break (exit) and continue (skip) statements for flow control in loops.