Jan 2, 2023

파이썬으로 2중 반복문을 활용한 구구단 및 문자열 formatting 종류 (Multiplication table using a double for-loop in Python)

print("구구단 2단부터 9단까지 시작!")

for i in range(2, 10, 1):
    for j in range(1, 10, 1):
        print(i, "x", j, "=", i*j)                   # case1
        print("%d x %d = %d"  % (i, j, i*j))         # case2
        print(f'{i} x {j} = {i*j}')                  # case3
        print("{0} x {1} = {2}".format(i, j, i*j))   # case4

Output exceeds the size limit. Open the full output data in a text editor
구구단 2단부터 9단까지 시작! 2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 3 x 1 = 3 3 x 2 = 6 3 x 3 = 9 3 x 4 = 12 3 x 5 = 15 3 x 6 = 18 3 x 7 = 21 3 x 8 = 24 3 x 9 = 27

No comments:

Post a Comment