-2

I have a door and there's a keypad code for it. If you get the code right you say Correct, if you get it wrong it just prints the wrong code (Just for debugging). However, I don't understand why nothing's happening when I code it. This is python btw:

realnumber = [12345]
inputnumber = []

def main():
  integer = input("Input a list of numbers to open the door:")

  if integer == realnumber:
    print(realnumber)
    print("Correct")
  else:
    inputnumber.append(integer)
main()
  • 1
    "I don't understand why nothing's happening when I code it" - please learn how to be more specific. Things seldomly happen when coding, did you mean when executing it? Is it really that nothing happens or are you confused because it runs but doesn't print anything? – weltensturm May 07 '21 at 16:09
  • 2
    you don't print anything in the "else". what do you expect to happen? – batman567 May 07 '21 at 16:14
  • Sorry, I meant that when you place an answer for the key pad number and its correct it won't print correct – Julian Deery May 07 '21 at 16:19
  • Also, answering your question batman567 I tried that but each time it just kept on printing the number even when its correct so it's like its skipping the if statement – Julian Deery May 07 '21 at 16:20
  • Please look at the values of `integer` and `realnumber` when you think they should match. Do they really match, or are they different? (Hint: strings and lists are different things.) – ChrisGPT was on strike May 09 '21 at 02:16

1 Answers1

0

This is largely guess work but two issues stand out to me here:

integer = input("Input a list of numbers to open the door:")

You may not be a aware that the variable named integer here is going to a string regardless of your input. Might I suggest you try:

integer = int(input("Input a list of numbers to open the door:"))

or even better, something like this to catch nonsense input:

try:
    integer = int(input("Input a list of numbers to open the door:"))
except ValueError:
    print("Invalid Input")

Secondly,

  if integer == realnumber:

Here you are trying to compare the variable "integer" (which is currently a string but with my suggested change will be an "int" variable) with realnumber, but realnumber is a list of variables that has only one input.

I suggest you choose one of these changes:

  if integer == realnumber[0]:

or

realnumber = 12345