通过while循环实现打印:
****
***
**
*
num1 += 1 line = 5 #while 循环嵌套 while line > 0: tmp = line while tmp > 0: print("*",end="") tmp -= 1 print() line -=1
用户输入对应的数字,来打印对应效果(有#组成的效果)
height = int(input("Height is :")) #用户输入一个高度 width = int(input("Width is :")) #用户输入一个宽度 num1 = height #step 1:赋值 while num1 > 0: #step 2: 满足条件 #step 12: num2 = width #step 3:赋值 while num2 > 0: #step 4:满足条件 step 7: print("#", end="") #step 5:不换行打印# step 8: num2 -= 1 #step 6:num2 自减 1 step 9: print() #step 10: 只是换行 num1 -= 1 #step 11:num1 自减 1
99乘法表 通过使用while循环,实现乘法表计算
num1 = 1 while num1 <= 9: num2 = num1 while num2 <= 9: print(str(num1) +"*" + str(num2) + "=" + str(num1 * num2),end =" " ) num2 += 1 print() num1 += 1