Reputation: 1
I have been making a code to try to respond to the user input as a joke to send to a friend. But everytime I input a passcode it prints 'Access Denied.' And I'm using Spyder to code it.
Here is the code:
import time
print "Please enter your name to acess file."
userName=raw_input();
print "Searching Database..."
time.sleep(0.5)
print "Searching Database.."
time.sleep(0.5)
print "Searching Database."
time.sleep(0.5)
print "Searching Database.."
time.sleep(0.5)
print "Hello {} please input passcode.".format(userName)
passCode=raw_input();
if passCode != 0000:
print 'Access Denied'
else:
print 'Access Granted'
Upvotes: 0
Views: 114
Reputation: 2355
Your comparison is wrong. You are comparing the string pass with the 0000
which is a number.
if passCode != '0000':
print 'Access Denied'
else:
print 'Access Granted'
0x5453
raw_input returns an object of type str, which should not be compared to an object of type int.
Upvotes: 3
Reputation: 1350
if int(passCode) != 0000: # notice the integer wrapper
print 'Access Denied'
else:
print 'Access Granted'
Make sure you are comparing the right types. You can also do this:
if passCode != '0000':
print 'Access Denied'
else:
print 'Access Granted'
Upvotes: 1