Home Python 'height' is not defined
Reply: 0

Python 'height' is not defined

user783 Published in May 24, 2018, 4:00 pm

Python is saying that the name 'height' is not defined, and I have no idea why that is, as according to my logic, I return the variable height, so I would be able to access it within my for loop?

Can someone point me in the right direction? Thanks. Edit: the get_int() is a function inside the cs50 library.

import cs50

def main():

    print("Enter a number between 0 and 26: ", end="")

    i = get_height("Enter height: ", end="")

def get_height():
    while True:
        height = get_int()
        if height <= 0 or height >= 23:
    return height

for i in range(height):
    print(" " * (height - i), end="")
    print("#" * (i + 2), end="")

if __name__ == "__main__":
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.389331 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO