0

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'
LeKhan9
  • 1,300
  • 1
  • 5
  • 15
  • 1
    Try looking at `passCode` to see what it actually contains. You might also want to try looking at its `type()` (i.e. by running `type(passCode)` and comparing it to `type(0000)`. – ChrisGPT was on strike Oct 19 '18 at 15:23
  • `if passCode != 0000:`? or `if passCode != 0:` or `if passCode != '0000':` – depperm Oct 19 '18 at 15:23

2 Answers2

3

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.

Petar Velev
  • 2,305
  • 12
  • 24
  • To elaborate, `raw_input` returns an object of type `str`, which should not be compared to an object of type `int`. – 0x5453 Oct 19 '18 at 15:29
1
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'
LeKhan9
  • 1,300
  • 1
  • 5
  • 15