[Python] My python code is returning "NameError: name 'settings' isn't defined"

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    I'm making a small game on a python calculator, so things might be a bit janky processing-wise.

    Python script:

    from math import *
    import time

    autoDisplay=True

    def settings():
    print("settingsAutoDisplay("+str(autoDisplay)+")")
    return

    def settingsAutoDisplay(settingInput):
    autoDisplay = not settingInput
    return


    Console log:

    >>> settings()
    Last command
    NameError: name 'settings' isn't defined
    >>> settingsAutoDisplay(True)
    Last command
    NameError: name 'settingsAutoDisplay' isn't defined


    I have a few functions before that, but they shouldn't get in the way, and I figured people wouldn't want a whole script dump.

    This is using https://www.numworks.com/simulator/ scroll down to find the python app, then create a new script, copy paste the code, exit and click the dots on the right to execute it.

    Solution: indent "return" into the function. e.g.

    def settingsAutoDisplay(settingInput):
    autoDisplay = not settingInput
    return

    Continue reading...

Compartilhe esta Página