Use the while loop to print out the nine-nine multiplication table in python

Use the python language to print out a nine-nine multiplication table, combined with the while loop statement, output nine rows and nine columns, pay attention to alignment.

# 定义外层循环的控制变量
i = 1
while i <= 9:
    # 定义内层循环的控制变量
    j = 1
    while j <= i:
        print(f"{
      
      j}*{
      
      i}={
      
      j * i}\t", end='')  # 加上end='',输出不换行;\t制表符进行对齐
        j += 1

    i += 1
    print()  # print(),输出一个换行

operation result:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44996886/article/details/132417980