Assignment, Variables, Constants & Sequences
Inputs, Outputs & Type Conversion
IF Statements & Boolean Operators
Nested Selection and Iteration
WHILE, REPEAT-UNTIL Loops
Validation and verification
Validation and authentication routines
High-level & Low-level languages
Assemblers, Compilers & Interpreters
There are two major types of loops in Python, for loops and while loops. If you want to repeat a certain number of times (definite count), you will normally use a for loop.
For example, a for loop can be used to print all student records since the computer knows exactly how many students there are.
for variable in range(number):
indented code goes here...
For loops will iterate through a sequence of numbers using the "range" function. The range function allows you to specify up to three values
range(start value, stop value, step value)
Below is an example of a for loop using the range function with just the stop value set to 5 so it will repeat the code inside the loop 5 times
You can use the range function in a for loop to print out numbers within a range you decide by setting both the
and the stop value.
Why 8 and not 7? Well because our range will stop when it gets to the stop value
Use the code window below
1. See if you can print out the range of numbers from 2 to 10.
2. Now ask the the user to enter two numbers and print out the range between those two numbers
For example if we set the step value = 2
1. See if you can print out all the positive even numbers up to and including 10.
2. Now ask the the user to enter three numbers and print out the range between those two numbers using the step value they have entered.