Python Forum
name "MyVariable" can be undefined - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: name "MyVariable" can be undefined (/thread-29153.html)



name "MyVariable" can be undefined - Advisability - Aug-20-2020

Hello, I am a new coder and am trying to make a short choose-your-own-adventure game in an attempt to learn the basics of python. no matter what i do, though, one of my variables keeps getting read as undefined. i am unsure on how to appropriately fix the issue, and i will paste a segment of the code here for review.
    while 4 < 5:
        while 5 > 6:
            setval = input("What Do you do?")
            if setval == 8:
                COURSEGET = 1
                print("This room is full of star charts and maps")
                print("With all of these, you can path your way home!")
                print("You return to the main room.")
                if setval == 7:
                    if COURSEGET == 1:
                        print("You punch in the code for home, and are saved from dying alone in space.")
                        COURSESET = "true"
                    else:
                        print("The Console is awaiting a flight course. You return to the main room")
                    if setval == 9:
                        if COURSESET == "true":
                            print("The Engine room is warm, and humming with energy.")
                            print("The start button on the engine is glowing red, but you haven't set a course yet.")
                            print("Better not press it. You return to the main room")
                        else:
                            print("You Press the start button on the engines, and the ship Rockets off.")
                            print("You safely arrive back in federal space, and are welcomed home.")
                            print("This'll make a helluva story for the kids.")
                            MAINVAL = "Extra"
                            if MAINVAL == "Extra":
                                print("Thank you for playing, please share this little adventure game of mine!")
                                break



RE: name "MyVariable" can be undefined - Gribouillis - Aug-20-2020

Something is really wrong with this code. The while 4 < 5 will loop indefinitely because the condition is always True, and everything under the while 5 > 6 will never be executed because the condition is always False.