CS50 Mario更感性的Python-不打印行

CS50 Mario更感性的Python-不打印行,python,cs50,Python,Cs50,我正在尝试编写CS50 Mario更加感伤的(Python),我遇到了一些问题。代码执行不正确,并产生以下问题: Results for cs50/problems/2020/x/sentimental/mario/more generated by check50 v3.1.2 :) mario.py exists. :) rejects a height of -1 :) rejects a height of 0 :( handles a height of 1 correctly

我正在尝试编写CS50 Mario更加感伤的(Python),我遇到了一些问题。代码执行不正确,并产生以下问题:

Results for cs50/problems/2020/x/sentimental/mario/more generated by check50 v3.1.2
:) mario.py exists.
:) rejects a height of -1
:) rejects a height of 0
:( handles a height of 1 correctly
    expected ""#  #"", not ""
:( handles a height of 2 correctly
    expected "" #  #"\n"##  ...", not ""
:( handles a height of 8 correctly
    expected ""       #  #"\...", not ""
:( rejects a height of 9, and then accepts a height of 2
    expected program to reject input, but it did not
:) rejects a non-numeric height of "foo" 
:) rejects a non-numeric height of "" 
To see the results in your browser go to https://submit.cs50.io/check50/74938be07d19fd3664e32b052c21717012088526
我不明白为什么它现在不会显示块

# make sure there is valid input
while True:
    try:
        # ask for input
        height = int(input("Height: "))

        # make sure height is greater than 0 and less than or equal to 8
        if height >= 1 and height <= 8:
            break

        # iterate through height
        for counter in range(height):
            print(" " * (height - 1 - counter), end="")
            print("#" * (counter + 1), end="")
            print(" " * 2, end="")
            print("#" * (counter + 1), end="")
            print(end="\n")

    # display error message is value entered is below or above 1 and 8
    except ValueError:
        print("Please enter a number between 1 and 8. ", end="\n")
#确保有有效的输入
尽管如此:
尝试:
#征求意见
高度=整数(输入(“高度:”)
#确保高度大于0且小于或等于8

如果高度>=1且高度不确定为什么需要while循环。尝试在不使用while循环的情况下从用户处获取高度输入,并检查h>=1&h=1和高度我不明白您的问题是什么(这可能与您没有问的问题有关)。你能解释一下你展示的代码有什么问题吗?您预期会发生什么以及实际发生的情况有何不同?我编辑了我的原始帖子,以定义我所看到的问题。在except块中,如果h>=0,您在try块中有代码中断,而在try块中,您将c设置为0:问题可能是您想要中断try块我编辑了try和exception块,并且现在我正在取得一些进展,但是,金字塔仍然没有建立…尝试将for循环移出while循环。
height = int(input("Height: "))
if height >= 1 and height <= 8:
        for counter in range(height):
            print(" " * (height - 1 - counter), end="")
            print("#" * (counter + 1), end="")
            print(" " * 2, end="")
            print("#" * (counter + 1), end="")
            print(end="\n")
else:
 print("Please enter height between 1 and 8")
 exit()