Sequences
#
# sequences.py
#
# Print multiples of 7
print("Multiples of 7")
for i in range(30):
if i%7 == 0:
print(i)
# Print multiples of 7 again using range(begin, end, step)
print("Multiples of 7")
for i in range(0, 29, 7):
print(i)
# Arithmetic sequences have a common difference. For example, the
# sequence {3, 10, 17, 24, ...} has common difference 7.
# Print an arithmentic sequence using its recursive formula.
print("Arithmetic sequence: recursive")
= 3
value for i in range(5):
print(value)
+= 7
value
# Print an arithmetic sequence using its explicit formula.
print("Arithmetic sequence: explicit")
for i in range(5):
print(3 + i*7)
Output:
Multiples of 7
0
7
14
21
28
Multiples of 7
0
7
14
21
28
Arithmetic sequence: recursive
3
10
17
24
31
Arithmetic sequence: explicit
3
10
17
24
31