Python学习日记-4-while循环输出矩形,三角形

利用两个while相嵌套,输出由#组成的任意长宽矩形和三角形

height = int(input("Pleaes input the heigut:"))
width = int(input("Pleaes input the width:"))

num_height = height
num_width = width

while num_height >= 1:
    num_width = width
    while num_width >= 1:
        print("#",end="")
        num_width-=1
    print()
    num_height-=1

程序运行图

height = int(input("Pleaes input the heigut:"))

num_height = 1
num_width = 1

while num_height <= height:
    num_width = 1
    while num_width <= num_height:
        print("#",end=" ")
        num_width += 1
    num_height += 1
    print()

这里写图片描述

猜你喜欢

转载自blog.csdn.net/wuli_xiaoran/article/details/81479119