试图制作一个三角形“ *”

时间:2018-12-14 12:39:49

标签: python python-3.x

这是我的代码,我不知道为什么它不起作用。

shape = str(input("Type of Shape: "))

if(shape == "Triangle"):
    height  = int(input("Enter a height: "))
    for i in range(height):
        for j in range(i+1):
            print("*", end = " ")

elif(shape != "Rectangle" or shape != "Triangle"):
    print("Unavailable shape, ask for valid shape")

如果您运行该程序并输入Triangle并输入高度(例如5),则会打印出:

* * * * * * * * * * * * * * *

我正在使用Python 3.6.3,所以我不知道这在其中是否起着重要作用。

1 个答案:

答案 0 :(得分:1)

您可以用以下一行替换inner for循环 print("*"*(i+1))

相关问题