编写一个程序,当输入python bigdigists.py 234234,会输出下列结果。
import sys Zero = [" *** ", " * * ", "* *", "* *", "* *", " * * ", " *** "] #把下面的list竖起来就跟这个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): #len("aadfs")作用是确定字符串“aadfs”的长度 number = int(digits[column]) digit = Digits[number] line += digit[row] + " " #通过使用加好合并字符串 column += 1 print(line) row += 1 except IndexError: #如果用户不输入命令,就会报出IndexError错误 print("usage: bigdigits.py <number>") except ValueError as err: print(err, "in", digits)
import sys print(sys.argv[0]) print(sys.argv[1]) print(sys.argv[2]) print(sys.argv[3])输入python test.py arg1 arg2 arg3
test.py arg1 arg2 arg3
原文地址:http://blog.csdn.net/a359680405/article/details/42835439