Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在用python制作星号金字塔时遇到了一个问题_Python - Fatal编程技术网

我在用python制作星号金字塔时遇到了一个问题

我在用python制作星号金字塔时遇到了一个问题,python,Python,问题来自于。它是用韩语写的 这是使用输入N制作N层金字塔的问题。 N的范围必须大于0且小于100 如果N超出范围,程序应打印“?” "입력' 意思是输入 '출력' 意味着产出 我认为我的代码显示我想要的金字塔没有问题,但是有一个案例我不能通过,我不知道那是什么 UserInput=int(input()) 如果UserInput>0且UserInput0且UserInput

问题来自于。它是用韩语写的

这是使用输入N制作N层金字塔的问题。
N的范围必须大于0且小于100
如果N超出范围,程序应打印“?”

"입력' 意思是输入
'출력' 意味着产出

我认为我的代码显示我想要的金字塔没有问题,但是有一个案例我不能通过,我不知道那是什么

UserInput=int(input())
如果UserInput>0且UserInput<100:
对于范围内的i(1,用户输入+1):
打印(“*(UserInput-i)+“*”*(2*i-1))
其他:
打印(“?”)
我不知道我的代码哪里有问题。 提供这个问题的网站说有一些案例无法通过

可能是什么问题?

您还需要输出尾随空格

此代码适用于:

UserInput = int(input())

if UserInput > 0 and UserInput < 100:
    for i in range(1, UserInput + 1):
        print(" " * (UserInput-i) + "*" * (2 * i - 1) + " " * (UserInput-i))

else:
    print("?")
UserInput=int(input())
如果UserInput>0且UserInput<100:
对于范围内的i(1,用户输入+1):
打印(“*(UserInput-i)+“*”*(2*i-1)+“*(UserInput-i))
其他:
打印(“?”)

令人惊讶!谢谢。但是我想知道有什么区别。。你能告诉我为什么吗?当你看例子3中的链接时,要输出的第一行是:[space]*[space]我用[space]替换了他们使用的符号,这代表一个空格字符。这意味着该任务还需要您在*仅代码输出:[space]之后输出空格*