工具ptcham
首先我們要理清設計思路,對於初學者來說,是否能夠熟練運用循環和嵌套,是能否做出本小程序的基礎,同時也要冷靜思考編程思路。以下是基於python的九九乘法表。希望能夠幫助初學者,理清思路,爲以後的進階打好基礎。
#定義一個函數,把輸出乘法表的功能封裝在個函數裏,需要的時候直接調用。
def chengfabiao():
#定義一個循環計數器
row = 1
#開始循環
while row <= 9:
col = 1
while col <= row:
# print("$",end="")
sum = row * col
print("%d * %d= %d\t" % (col, row, sum), end=" ")
col += 1
print("")
row += 1
chengfabiao()