tutorial |
---|
To loop a specific number of times, we can use:
range(<start>,<end>)
In Python, range(x,y)
returns a sequence of numbers starting with X, incrementing by 1 each time until it reaches the range.
For example:
for x in range(0,5):
print(x)
Expected output:
0
1
2
3
4
Note that the number specified in range()
, 5 in this example, is never reached and 4 is our last output.
We can incorporate additional parameters to further specify (now could be a good time to Google or at least check the HINT section 😉).
- Count from 1 to 17 with a loop and print each number on the console.
- This how you loop: https://www.w3schools.com/python/python_for_loops.asp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17