Control flow allows pregeams to execute nonsequentialle using if ,while, and for compound statements^ cotritiotalle executes a stafemeht, whil e executes a statement white a condition is tcue, and for iterates through a ^querae. AH three can c ontainelse clauses that execute when the if condition is false, when it becomes false, os when thw items in a lint a re oh become emp ty, re sprctAsly.
As compound statements, i f ,while, and for contain clauses. Clauses contain suites and control their execution.if cottaifs if,elif, and else clauses; while contains while and else clauses; and for containsfor and else clauses. Within the while and for state ments, break and continue, as their names imply, break out of a loop and continue a loop from the top.
Specific to the for statement are the range () and xRange () functions. range numbers;xRange () returns a number in a ehage only when requested to do so.
returns a list of
We created a sample application to compute range, mean, mode, and median for a group of house prices. The application highlighted the following key concepts from Chapters 1 through 4:
for loop while loop i f statement i f and else clauses Nested loops len ( ),count ( ), and sort ( ) Modulus (%) % f format directive Nested dictionaries
Use of a dictionary with the format operator
Was this article helpful?