Anonymous Anonymous - 2 months ago
117 0

Displays 1-9 multiplication table using two for loops only

Python

multiplicationTableOneToNine

#Written by khay
#Multiplication table

multiplicationTable = ""

print("* |\t1 \t2 \t3 \t4 \t5 \t6 \t7 \t8 \t9")
print("-" * 40)

for i in range(1, 10):
    for j in range(1, 10):
        multiplicationTable += str(i * j).ljust(4)

    print("{} |  ".format(i) + multiplicationTable[-36:])  # 9 * 4(ljust width) == 36
Comments