Home > Mobile >  Printing 2048 board in python with spacing with standard libraries
Printing 2048 board in python with spacing with standard libraries

Time:09-23

I want to print a 2048 board with proper spacing.

I was able to reach till here.

╔═══╤═══╤═══╤═══╗
║ 1234 ║
╟───┼───┼───┼───╢
║ 3245 ║
╟───┼───┼───┼───╢
║ 1142 ║
╟───┼───┼───┼───╢
║ 6543 ║
╚═══╧═══╧═══╧═══╝

But when I give larger numbers, it does not look good.

╔═══╤═══╤═══╤═══╗
║ 1125634 ║
╟───┼───┼───┼───╢
║ 324123 ║
╟───┼───┼───┼───╢
║ 1142 ║
╟───┼───┼───┼───╢
║ 6204843 ║
╚═══╧═══╧═══╧═══╝

How can I achieve this with only standard libraries?

Thanks!

Edit

I know that we can use prettytable but I also want to print it colorful. So I cant use prettytable.

Edit 2

My code -

print('\n'.join([
            '╔═══╤═══╤═══╤═══╗',
            '║ {} │ {} │ {} │ {} ║'.format(*board[0]),
            '╟───┼───┼───┼───╢',
            '║ {} │ {} │ {} │ {} ║'.format(*board[1]),
            '╟───┼───┼───┼───╢',
            '║ {} │ {} │ {} │ {} ║'.format(*board[2]),
            '╟───┼───┼───┼───╢',
            '║ {} │ {} │ {} │ {} ║'.format(*board[3]),
            '╚═══╧═══╧═══╧═══╝'
]))

CodePudding user response:

I don't think you can achieve this in such a simple way. My guess would be to :

  • Related