您好,登錄后才能下訂單哦!
下面通過一段代碼給大家介紹python 使用for 循環實現九九乘法表,具體代碼如下所示:
#for 循環實現99乘法表 for i in range (1,10): for j in range (1,i+1): print("{}*{} = {:<4}".format(i,j,i*j),end = " ") print("") print('第1種'+"-"*96) for i in range (9,0,-1): for j in range (1,i+1): print("{}*{} = {:<4}".format(i, j, i * j), end=" ") print("") print('第2種'+"-"*96) for i in range (1,10): for k in range (1,i): print(end = " ") for j in range (i,10): print("{}*{} = {:<4}".format(i,j,i*j),end = " ") print("") print('第3種'+"-"*96) for i in range (9,0,-1): for k in range (1,i): print(end = " ") for j in range (i,10): print("{}*{} = {:<4}".format(i,j,i*j),end = " ") print("") print('第4種'+"-"*96) for i in range (1,10): for j in range (1,10): print("%d*%d=%2d" % (i,j,i*j),end = " ") print("") print('第5種'+"-"*96) for i in range (1,10): for j in range (i,10): print("%d*%d=%2d" % (i,j,i*j),end = " ") print("") print('第6種'+"-"*96) for i in range (9,0,-1): for j in range (1,i+1): print("%d*%d=%2d" % (i,j,i*j),end = " ") print("") print('第7種'+"-"*96) for i in range (1,10): for k in range (1,i): print(end = " ") for j in range (i,10): print("%d*%d=%2d" % (i, j, i * j), end=" ") print("") print('第8種'+"-"*96) for i in range (1,10): for k in range (1,10-i): print(end = " ") for j in range (i,0,-1): print("%d*%d=%2d" % (i, j, i * j), end=" ") print("") print('第9種'+"-"*96)
總結
以上所述是小編給大家介紹的Python用for循環實現九九乘法表,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。