введите сюда код #!/usr/bin/env python3 import sys Zero = ["00" "0 0" "0 0" "0 0" "00"] One = ['1', '1 1', '1', '1', '111'] Two = ['2', '2 2', '2', '2', '22222' ] Three = ['3', '3 3', '3', '3 3', '3'] Four = ['4', '4 4', '4444444', '4', '4'] Five = ['55555', '5', '5 5', '5', '5 5',] Six = ['6 6', '6', '6 6 6', '6 6', '6'] Seven = ['7777777', '7', '7', ' 7', '7'] Eight = ['8', '8 8', '888', '8 8', '8'] Nine = ['9 9', '9 9', '9 9', '9', '9 9'] Digits = [Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine] try: digits = sys.argv[1] row = 0 while row < 1: line = "" column = 0 while column < len(digits): number = int(digits[column]) digit = Digits[number] line += digit[row] + " " column += 1 print(line) row += 1 except IndexError: print("usage: bigdigits.py <number>") except ValueError as err: print(err, "in", digits) 

I need to output numbers to the console. and it happens to me like this: 000 00 00 000 111 11 11 111 2222 ... something like this.

I tried it

 Zero = ["""00 0 0 0 0 0 0 00"""] 

but did not help.

I use Python 3.5.

2 answers 2

Note that:

 one_string = [ " 00 " "0 0" "0 0" "0 0" " 00 "] 

and

 many_strings = [ " 00 ", "0 0", "0 0", "0 0", " 00 "] 

these are different things:

  • one_string is a list containing a single string consisting of the union of the given constants (separated by a space in the source code):

     one_string == [' 00 0 00 00 0 00 '] 

    In Python: ("a" "b") == "ab" - string constants (literals) are combined if there is only a space between them (including tabs, a new line, etc.). This does not apply to variables: ab == ab is a SyntaxError

  • many_strings is a list containing many strings (separated by commas in the source code):

     many_strings == [' 00 ', '0 0', '0 0', '0 0', ' 00 '] 

You want the second option:

 print(*many_strings, sep='\n') 

See What does it mean * (asterisk) and ** double star in Python?

Result

  00 0 0 0 0 0 0 00 

Note that I added spaces for the first and last lines.

    In Python3, you can use str.format () to align a string with the required number of characters in a string. Those. Such a structure will independently format the output to a string with a width of n characters and make alignment left, right, or center. For example, the question does not have more than 7 characters per line, so you can make 7 characters per line and center alignment, like this:

     many_strings = [ "00", "0 0", "0 0", "0 0", "00"] for s in many_strings: print("{:^7}".format(s)) 

    Result

      00 0 0 0 0 0 0 00