Pure Programmer
Blue Matrix


Cluster Map

Selection

L1

This page is under construction. Please come back later.

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

# Begin Main
print("Start...")
if (len(sys.argv) != 3) :
	print("You need at least two command line arguments!")
print("Finish...")

Output
$ python3 Selection1.py abc Start... You need at least two command line arguments! Finish... $ python3 Selection1.py abc 123 Start... Finish...
Selection2.py
#!/usr/bin/env python3;
import Utils
import sys

# Begin Main
x = Utils.stoiWithDefault(sys.argv[1], 0)
print("Start...")
if (x > 10) :
	print("Greater than 10")
else :
	print("Less than or equal to 10")
print("Finish...")

Output
$ python3 Selection2.py 8 Start... Less than or equal to 10 Finish... $ python3 Selection2.py 12 Start... Greater than 10 Finish...
Selection3.py
#!/usr/bin/env python3;
import Utils
import sys

# Begin Main
x = Utils.stoiWithDefault(sys.argv[1], 0)
print("Start...")
if (x > 1000) :
	print("Greater than 1000")
elif (x > 100) :
	print("Greater than 100 but less than or equal to 1000")
else :
	print("Less than or equal to 100")
print("Finish...")

Output
$ python3 Selection3.py 12 Start... Less than or equal to 100 Finish... $ python3 Selection3.py 120 Start... Greater than 100 but less than or equal to 1000 Finish... $ python3 Selection3.py 1200 Start... Greater than 1000 Finish...
Selection4.py
#!/usr/bin/env python3;
import Utils
import sys

# Begin Main
x = Utils.stoiWithDefault(sys.argv[1], 0)
for case in Utils.switch (x) :
	if case(1) :
		print("One")
		break
	if case(2) :
		print("Two")
		break
	if case(3) : pass
	if case(4) :
		print("Three or Four")
		break
	if case() :
		print("Just don't know!")
		break

Output
$ python3 Selection4.py 0 Just don't know! $ python3 Selection4.py 1 One $ python3 Selection4.py 2 Two $ python3 Selection4.py 3 Three or Four $ python3 Selection4.py 4 Three or Four
Selection5.py
#!/usr/bin/env python3;
import Utils
import sys

# Begin Main
x = sys.argv[1][0]
x = x.lower()
for case in Utils.switch (x) :
	if case("a") : pass
	if case("e") : pass
	if case("i") : pass
	if case("o") : pass
	if case("u") :
		print("{0:c} is a vowel".format(ord(x[0])))
		break
	if case("y") :
		print("y is sometimes a vowel")
		break
	if case() :
		print("{0:c} is a consonant".format(ord(x[0])))
		break

Output
$ python3 Selection5.py a a is a vowel $ python3 Selection5.py g g is a consonant $ python3 Selection5.py I i is a vowel $ python3 Selection5.py T t is a consonant $ python3 Selection5.py y y is sometimes a vowel
python

Questions

Projects

More ★'s indicate higher difficulty level.

References