第一个完整的python程序,虽然很简单,但是比hello,world复杂点。。。
在大量用户共享高速行式打印机的站点上,使用这种方法很常见,为每个用户的打印作业打印一个引导页。
代码如下:
#!/usr/bin/env python3
import sys
Zero = [" *** ",
" * * ",
"* *",
"* *",
"* *",
" * * ",
" *** "]
One = [" * ", "** ", " * ", " * ", " * ", " * ", "***"]
Two = [" *** ", "* *", "* * ", " * ", " * ", "* ", "*****"]
Three = [" *** ", "* *", " *", " ** ", " *", "* *", " *** "]
Four = [" * ", " ** ", " * * ", "* * ", "******", " * ",
" * "]
Five = ["*****", "* ", "* ", " *** ", " *", "* *", " *** "]
Six = [" *** ", "* ", "* ", "**** ", "* *", "* *", " *** "]
Seven = ["*****", " *", " * ", " * ", " * ", "* ", "* "]
Eight = [" *** ", "* *", "* *", " *** ", "* *", "* *", " *** "]
Nine = [" ****", "* *", "* *", " ****", " *", " *", " *"]
Digits = [Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine]
try:
digits = sys.argv[1]
row = 0
while row < 7:
line = ""
column = 0
while column < len(digits):
number = int(digits[column])
digit = Digits[number]
for char in digit[row]:
if(char=='*'):
char=str(number)
line += char
line += " "
column += 1
print(line)
row += 1
except IndexError:
print("usage: bigdigits.py ")
except ValueError as err:
print(err, "in", digits)
运行结果: