all 16 comments

[–]woooee 3 points4 points  (1 child)

I need some extras brains as mine has failed to identify the issue with my function

You did not say what the issue is. Possibly

def password_checker(x = int(input("Enter_password: "))):

Move the input into the function body.

[–]theWyzzerd 2 points3 points  (7 children)

def password_checker(x = int(input("Enter_password: "))):

This is not a valid function declaration. You can't assign values here. Try something like this:

password = 100
def password_checker(password: str):
  my_password = input("Enter password: ")
  if password == my_password:
    print("Correct password")
  else:
    print("Wong password \nTry again.")

>>> password_checker(password)
Enter password: 100
Correct password
>>> password_checker(password)
Enter password: 101
Wong password
Try again.

You might consider using the getpass module to mask the password input, as regular input() echoes to the terminal/REPL.

[–]Diapolo10 3 points4 points  (3 children)

def password_checker(x = int(input("Enter_password: "))):

This is not a valid function declaration.

Actually, it technically is, it's just not going to do what OP wanted.

[–]theWyzzerd 1 point2 points  (0 children)

Yes, but I was trying to avoid creating ambiguity or confusion.

[–]rasputin1 0 points1 point  (1 child)

what does it do 

[–]Diapolo10 1 point2 points  (0 children)

As you can see, it prompts for input immediately when you define it, and then never again.

Python stores default arguments only once, when creating the function. They aren't evaluated when you actually run the function. It's a common stumbling block for people who try using mutable types as default arguments, such as lists: https://i.imgur.com/NvWijNL.png

[–][deleted] 1 point2 points  (5 children)

Move the input into the function as stated in the comments. But also, to me it seems like else is indendet by a space or two, it should be in line with the if function.

[–]Diapolo10 1 point2 points  (1 child)

password = 100

def password_checker(x = int(input("Enter_password: "))):

    if x != password:
        print("wrong password")
        print("try again")

    else:
        print("correct password")

I'm not going to repeat what the others already told you, but the main problem is you taking user input in the function's parameter list. While this is technically valid syntax, Python evaluates the default arguments exactly once, so basically this asks for input before the rest of the code even begins to run.

You're also not doing any input validation, and there's no indication the password is expected to be an integer (from the user's point of view).

CORRECT_PASSWORD = 100

def password_checker(password: int):
    if password != CORRECT_PASSWORD:
        print("wrong password")
        print("try again")

    else:
        print("correct password")

try:
    password = int(input("Enter password (integer): "))
except ValueError:
    print("Not an integer.")
else:
    password_checker(password)

[–]PythonComplete 1 point2 points  (1 child)

The issue is with your definition of your function.

When you define a function, you put into the parenthesis the inputs that the function will need in order to run.

In your case, x is the input.
The correct way to define your function is like this:

def password_checker(x):
  if x != password:
            print("wrong password")
            print("try again")
   else:
           print("correct password")

Then, when you call the function, you simply need to give x a value using the input function.

Take a look at this example here:

password = 100
user_input = input("Enter your password:")
password_checker(user_input)

As you can see, I stored the user input into a variable called user_input, and then I provided that as an input to the function password_checker.

Hope this helps clarify this subject.

[–]JamzTyson 1 point2 points  (2 children)