风-fmgao

导航

python 9*9示例

# 9*9 乘法表
# def nine_nine():
#     for i in range(1, 10):
#         for j in range(1, i+1):
#             print('%d * %d = %d ' % (j, i, i*j), end='\t')
#         print('')
#
#
# nine_nine()


# # 右下三角
# def nine_nine():
#
#     for i in range(1, 10):
#         for k in range(1, 10 - i):
#             print(end="       ")
#         for j in range(1, i + 1):
#             product = i * j
#             print("%d*%d=%2d" % (i, j, product), end=" ")
#         print(" ")
#
#
# nine_nine()

# while 实现
# def nine_nine():
#     i = 1
#     while i < 10:
#         j = 1
#         while j <= i:
#             print("%d*%d=%-2d " % (j, i, i * j), end="")
#             '''''
#             print("%d*%d=%d  "%(j,i,i*j),end="")
#             if i*j<10:
#                 print(" ",end='')
#             '''
#             j += 1
#         print("")
#         i += 1


# nine_nine()

# 一行实现
# print("\n".join("\t".join(["%s*%s=%s" % (x, y, x * y) for y in range(1, x + 1)]) for x in range(1, 10)))


# 倒序
# def nine_nine():
#     for i in range(9, 0, -1):
#         for j in range(i, 0, -1):
#             print(str(i) + str("*") + str(j) + "=" + str(i * j), end="\t")
#         print()
#
#
# nine_nine()

# for+ while

# def nine_nine():
#     for x in range(1, 10):
#         y = 1
#         while y <= x:
#             print("%s*%s=%s " % (y, x, x * y), end="")
#             y += 1
#         print()
#
#
# nine_nine()

posted on 2018-05-22 13:50  风-fmgao  阅读(432)  评论(0编辑  收藏  举报