1

Alright so here's the code

def user_password():
input('Please Enter Password: ')

#profiles
def intercept():
    user_password()
    if user_password == "intercept":
            print("this is working so far")
    else:
            print("Incorect Password")
def Jimmy():
    user_password()
    if user_password == "Jimmy":
            print("this is working so far")
    else:
            print("Incorect Password")
def Tommy():
    user_password()
    if user_password == "Tommy":
            print("this is working so far")
    else:
            print("Incorect Password")

#login
user_functions = dict(
    intercept=intercept,
    Jimmy=Jimmy,
    Tommy=Tommy,
    # ...
)
 user_input = input("Input function name: ") 

if user_input in user_functions:
    user_functions[user_input]()
else:
    print("Error: Unknown function.")

PROBLEMS:

  • My code always starts with asking for the password even though I don't want it to.
    • When I change the first variable to a function it fixes this
    • Why does it execute when I'm just setting the variable. I'm pretty sure I shouldn't have to use a function instead of a variable
  • No matter what it always ends up as Incorrect Password even if I give the correct password
2
  • 2
    Since your first line of code is "user_password = input('Please Enter Password: ')" that's gonna be the first line to execute Commented Apr 23, 2017 at 1:55
  • = doesn't mean "make the thing on the left shorthand for the operation on the right". It means "do the thing on the right, and make the thing on the left a name for the object produced by doing the thing on the right". Commented Apr 23, 2017 at 1:56

1 Answer 1

3

I think you are trying to write something like that:

def get_user_password():
   return input('Please Enter Password: ')


def Jimmy():
    user_password = get_user_password()
    if user_password == "Jimmy":
            print("this is working so far")
Sign up to request clarification or add additional context in comments.

3 Comments

Would you mind explaining how that works and why my code didn't work? Go over the code first pls cause I changed some stuff
@intercept your first line is a SyntaxError. Please find how to define a function and how to set a variable. def user_password = input('Please Enter Password: ') is doing none to these.
even if i do it correctly it says incorrect password

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.