"尝试做一个三角形"

2024-04-24 02:47:36 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码,我不知道为什么不起作用。。你知道吗

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")

如果运行程序并键入三角形,然后键入5这样的高度,则打印出来:

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

我使用的是python3.6.3,所以我不知道这是否起到了很大的作用。你知道吗


Tags: ofin密码forinput键入iftype