pythonpython-3.xvariablessettings

Changing variables in python


I'm trying to make a setting section in my code where the user can change the setting which is already preset. But I'm not sure how i can make the input overwrite the already preset variable.

This is what I tried, but it doesn't work, I'm not sure how to overwrite the variable and then keep it constant so it wont change unless the program has ended.

centreLine = 109

while True:
    print("| [1] Centre line on screen")
    print("| [2] Change username")
    print("| [3] Change password")
    print("| [BACK]")
    print("| > ")

    settingsInput = input("")
    if settingsInput == "1":
        print("| Change centre line to: ")
        inputCentreLine = input()

        inputCentreLine = centreLine
# I have no clue ^^^^^^^^^^^^

I want to overwrite 'centreLine' from 109 to whatever the user changes it too, eg/: 42, which would change 'centreLine = 109' to 'centreLine = 42'.


Solution

  • With the line inputCentreLine == (centreLine) you're using the == operator which compares the two values and returns a boolean value based on whether the two sides are equal or not, a value which you're not doing anything with, so the line does nothing. Additionally, it looks like you're trying to overwrite the centreLine variable but have it backwards. Flip it and change it to centreLine = inputCentreLine and that will overwrite centreLine with the input value.