Reputation: 129
So I'm still relatively new to Python programming and so at the moment I'm just trying to create a simple password program. If the use has opened the program before, then it will skip the create a password bit. I have done this by creating a file which will contain the number of times the file has been opened. If the number is less than 1 then it will ask for the new password.
This bit works fine, I just have the problem that when running the following code, "None" is printed. I understand the whole function return bit but the code I'm using isn't in a function so I'm not sure why it is happening. Would really appreciate help in fixing this!
fo = open("openNo.txt", "r")
openNo = fo.read()
if int(openNo)<1:
pw = input(print("Please enter a password: ")) #creating a new password
pwCheck = pw
else:
pwCheck = input(print("Please enter your password: ")) #using an existing password
fo.close()
if pwCheck == "password":
print("Welcome!")
else:
print("access denied")
Upvotes: 0
Views: 49
Reputation: 1943
print("Please enter a password: ") returns none so you are seeing none when you run the code
Upvotes: 0
Reputation: 599788
You are doing that, in fact: you are passing the result of print
to input
. There's no need to do that.
pw = input("Please enter a password: ")
Upvotes: 1