Skip to main content
1 of 2

PSET 6: Sentimental [Mario.py(less)]: How exactly do I "reject input" in Python as specified in check50?

this is my first time posting on here and I'm trying to not break any rules but sorry if I do.

So, I followed the specification to make mario.py ( they are the same ones for mario.c ) in Sentimental in Pset6. My program works for everything except the last two condition which I will post below

:( rejects a non-numeric height of "foo" expected program to reject input, but it did not :( rejects a non-numeric height of "" expected program to reject input, but it did not

I feel like my program's logic makes sense, it outputs "Error: type an integer" when the user inputs a non-numeric height, but that doesn't the check50.

Here is my code:

try :
    height = int(input("Height:"))
    while height < 0 or height > 23:
        height = int(input("Height:"))
except ValueError:
    print ("Error: type an integer")

else:
    for i in range((height-1),0,-1):
        j = i-1
        k = height-j
        print(' '*j,'#'*k)
    print('#'*(height+1))

I don't necessarily care too much about passing check50 because the rules aren't even that clear for this specific problem. It's just I'm on pset 6 which is the transition from C to Python I want to transfer my knowledge accurately.

I feel like this situation is implying I return an error (return -1 in C), is the way I did that the correct way to do so in python? Or are there different/ more pythonic ways to return an error ( reject the input )?

Thanks so much!