def main():
x = 0
while x not in range (1,23):
getheight()
if x in range (1,23):
break
for i in range (x):
for j in range (x - j):
print (" ", end="")
for j in range (x):
print ("#", end="")
print (" ", end="")
for j in range (x):
print ("#", end="")
"\n"
def getheight():
x = input("Give me a positive integer no more than 23 \n")
return x
if __name__ == "__main__":
main()
1 Answer
x
is always 0 in the while loop. Scope. The x
that gets input in the getheight
function is local to the function.
If you change it to something like x = getheight()
, be aware from the python doc on input():
The function then reads a line from input, converts it to a string (stripping a trailing newline),
so x is never in range (1,23)