用來練手的python 練習題,原鏈接 : python練習實例8
題干: 輸出 9*9 乘法口訣表。
import numpy as nptable = np.zeros((9,9))
for i in range(table.shape[0]):for j in range(table.shape[1]):table[i][j] = (i+1) * (j+1)# 查詢九九乘法表
def affichage_table(a,b):print("%d, %d 的乘積是 : %d"%(a,b,table[a-1][b-1]))# 完整輸出乘法表
def affichage_all():for i in range(table.shape[0]):print("\n")for j in range(table.shape[1]):print("%d * %d = %d"%(i+1,j+1,table[i][j]))
查詢輸出:
affichage_table(8,9)
完整輸出:
affichage_all()
… … …
小tips : 這個例題需要注意的點就一個,就是Python中的矩陣,向量的索引都是從0開始的。