Tooltip
These resources have been reviewed and selected by STEM Learning’s team of education specialists for factual accuracy and relevance to teaching STEM subjects in UK schools.

Python 3: Iteration

For students with some prior experience of using simple For and While loops, this intermediate-level resource explores how they can be used for more complex coding while maintaining efficiency.

Exercises include arithmetic applications of While loops, and development of simple For loops to be usable in more flexible ways. Use of Break in For and While loops is covered, and Else is used for conditionally branching code. Guidance is included for using In with For loops, to iterate over items in a list.

Functions that check data validity are introduced in code that generates error messages, and are combined with the Continue function to build more robust programs.

Some simple tutorials and exercises using Range () include conversions to lists and printing values, as well as stepping through ranges using positive and negative numbers. The reversed() function is applied to ranges, too, as are a selection of other functions that can be used with ranges, lists and strings.

Show health and safety information

Please be aware that resources have been published on the website in the form that they were originally supplied. This means that procedures reflect general practice and standards applicable at the time resources were produced and cannot be assumed to be acceptable today. Website users are fully responsible for ensuring that any activity, including practical work, which they carry out is in accordance with current regulations related to health and safety and that an appropriate risk assessment has been carried out.

Information on the permitted use of this resource is covered by the Category Three Content section in STEM Learning’s Terms and conditions.

Lists that tag this content