Pure Programmer
Blue Matrix


Cluster Map

Iteration

L1

This page is under construction. Please come back later.

Iteration1.py
#!/usr/bin/env python3;
import Utils
import sys

# Begin Main
max = 5
if (len(sys.argv) == 2) :
	max = Utils.stoiWithDefault(sys.argv[1], 5)
for i in range(0, max) :
	print("Hello, world!")

Output
$ python3 Iteration1.py 5 Hello, world! Hello, world! Hello, world! Hello, world! Hello, world!
Iteration2.py
#!/usr/bin/env python3;
# Begin Main
for i in range(10, 1 + -1, -1) :
	print(str(i))
print("Blastoff!")

Output
$ python3 Iteration2.py 10 9 8 7 6 5 4 3 2 1 Blastoff!
Iteration3.py
#!/usr/bin/env python3;
# Begin Main
print("Even numbers up to 100...")
for i in range(2, 100 + 2, 2) :
	print(str(i))

Output
$ python Iteration3.py Even numbers up to 100... 2 4 6 8 10 12 14 16 18 ... 82 84 86 88 90 92 94 96 98 100
Floating point ranges are not a built-in part of Python. You will need to install the pip module numpy to use them.
$ sudo pip install numpy
Iteration4.py
#!/usr/bin/env python3;
import numpy

# Begin Main
print("Floating point numbers")
for d in numpy.arange(1.0, 2.01, 0.1) :
	print(str(d))

Output
$ python3 Iteration4.py Traceback (most recent call last): File "/Users/rich/Desktop/Resources/pureprogrammer/py/examples/Iteration4.py", line 2, in <module> import numpy ModuleNotFoundError: No module named 'numpy'
Iteration5.py
#!/usr/bin/env python3;
# Begin Main
print("Powers of 2 up to 256!")
i = 1
while i <= 256 :
	print(str(i))
	i *= 2

Output
$ python3 Iteration5.py Powers of 2 up to 256! 1 2 4 8 16 32 64 128 256
Iteration6.py
#!/usr/bin/env python3;
# Begin Main
s = "Hello, world! 🥰🇺🇸"
for c in s :
	print(str(c))

Output
$ python3 Iteration6.py H e l l o , w o r l d ! 🥰 🇺 🇸

Iterators

python

Questions

Projects

More ★'s indicate higher difficulty level.

References