iT邦幫忙

1

簡易練習-3 99乘法表

用for迴圈, range()

for i in range(1, 10):
    for j in range(1, 10):
        num = i * j
        print('%d x %d = %d' %(i, j, num))
    print('\n')

用for迴圈, 但自定義list, 不使用range()

list = [1,2,3,4,5,6,7,8,9]
for i in list:
    for j in list:
        num = i * j
        print('%d x %d = %d' %(i, j, num))
    print('\n')

用while迴圈

i = 1
while i < 10:
    j = 1
    while j < 10:
        num = i*j
        print('%d x %d = %d' %(i, j, num))
        j += 1
    i += 1
    print('\n')

尚未有邦友留言

立即登入留言