IFB104 Lecture 5: IFB104 Lecture 5

127 views3 pages
8 Nov 2018
School
Course
Professor

Document Summary

Example of repeating an action for each item in a list. As a major demonstration involving a foreach loop, here we will develop a program which follows instructions stored in a list to draw complex pictures. It also refreshes our understanding of conditional statements, if-elif-else, from last week. Simple for-each loops: we have already seen how to do the same action several times using a for-each loop and the built-in range function. In python this is often combined with the len function to do a repeated action for however many items there are in a sequence. Accessing sequence values in for-each loops: the target variable in the for-each statement can be used in the loop body just like any other variable. More on the range function in for-each statements: the range function can be used in for-each statements to access items in sequences via their position.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents