Multiplication tables: Difference between revisions

Line 333:
=={{header|Python}}==
<lang python>>>> size = 12
>>> width = len(str(size**2))
>>> for row in range(-1,size+1):
if row==0:
print("─"*3width + "┼"+"─"*(4(width+1)*size-1))
else:
print("".join("%3s*s%1s" % ((width,) + (("x","│") if row==-1 and col==0
else (row,"│") if row>0 and col==0
else (col,"") if row==-1
else ("","") if row>col
else (row*col,"")))
for col in range(size+1)))
 
Line 364 ⟶ 365:
Declaring a file type of UTF-8 and adding a u to all string literals to transform them into Unicode literals would make the above work in Python 2.X.
<small>(As would using ASCII minus, plus, and pipe characters: "-", "+", "|"; instead of the non-ASCII chars used to draw a frame)</small>.
 
The code works fine for all values of integer <code>0 <= size <= 31</code> as above that, table numbers can get greater than the three digits allotted to them in the output formatting. This is a reasonable limitation for this format of multiplication table as other considerations, such as the width of the printed line are also excessive for large values of <code>size</code>.
 
=={{header|Ruby}}==
Anonymous user