[6 kyu] Multiplication table

panzhong171發表於2020-11-01

[6 kyu] Multiplication table

Question

在這裡插入圖片描述

Sample Test

在這裡插入圖片描述

My Answer (accepted)

def multiplication_table(size):
    bl = list()
    for i in range(1, size+1):
        sl = list()
        for j in range(1, size+1):
            sl.append(i*j)
        bl.append(sl)
    print(bl)
    return bl

Suggested Answer

def multiplicationTable(size):
    return [[j*i for j in range(1, size+1)] for i in range(1, size+1)]

相關文章