-1

I am trying to make a password script in python that makes it so that if you insert the right password then it turns passwordAccepted to 1 and the other script would work.

Variables.py

passwordAccepted = 0

Password.py

import Variables

password = "" #Enter your password
userInput = input("What is your password?\n")
if userInput == password:
    print("Access Granted")
    Variables.passwordAccepted = 1
else:
    print("Access Denied")
    Variables.passwordAccepted = 0

Player.py

from Variables import passwordAccepted

class Player:
    Inventory = []
    Level = 1
if passwordAccepted == 1:
    option = input("What do you want to see?\n1. Inventory\n2. Level\n\n")
    if option == "Inventory":
        print("\nYou have:")
        for x in Player().Inventory:
            print(x)
    elif option == "Level":
        print("\nYou are level", Player().Level)
    else:
        print("Either type in \"Inventory\" or type in \"Level\"")

I am also new to python but tried using from to import only the variable and tried to import the variable from Variable.py to Password.py and then to Player.py.

FirstFox
  • 1
  • 1

1 Answers1

-1

In player.py replace:
from Variables import passwordAccepted with from Password import Variables and then replace all passwordAccepted in your code with Variables.passwordAccepted.

This should work, because when you change a variable in a file then this file will not change, you change the value of the variable only in your code. If you then try to import this file it will import it, but the value will be the same (in your code 0).

NotMEE12
  • 74
  • 7