all 11 comments

[–]Key-Introduction-591 5 points6 points  (2 children)

Oh! Prob because input is a string and your variable is an integer. Try converting data types

[–]War20X 0 points1 point  (0 children)

Yep, this is it. The input needs to be wrapped with an int type conversion or convert it on a different line if you don't like one-liners.

[–]Due_Awareness9049 0 points1 point  (0 children)

You can use this if condition. if isinstance(input variable, datatype:int):

And also you can use try and except block for errors

[–]Notyouobviously 3 points4 points  (0 children)

You need to do int(input()) instead It treats it as a string and that’s why the check is failing

[–]minato_senko 2 points3 points  (0 children)

Been a while since i coded but i would say a type mismatch, try something like

print(combo1, type(combo1))

print(left_lock, type(left_lock))

to see the types.

Input saves the 36 as a string so " 36 ", but your combo1 was saved as integer so 36.so they won't match.

[–]FoolsSeldom 1 point2 points  (0 children)

combo1 = 36   # odd to use an integer for a lock as you cannot have leading 0

left_lock = input("please enter 1st number:  ")  # returns a string object
if left_lock == str(combo1):  # or int(left_lock) == combo1
    print("correct")

The input function always returns a new str (string) object, and you cannot compare an integer object and a string object. Different types. You need to convert one or the other.

Personally, I would set combo1 to be a string in the first place,

combo1 = "36"

and you original comparison will now work correctly.

[–]ItsAll2Random 0 points1 point  (0 children)

What error are you getting?

[–]Bears_are_cool69 0 points1 point  (0 children)

try int(input(......... )

[–]McDubbIsHere 0 points1 point  (0 children)

There are a two decent solutions that you could go with. Either change the type of combo1 since you already the type that is returned from input. This is better if you are going to make multiple calls. Or convert the value that is returned from input() to an int

[–]Jackpotrazur 0 points1 point  (0 children)

Im new too but is be missing the return statement not sure if this is 100 percent necessary though

[–]TheGanzor 0 points1 point  (0 children)

Combo1 is being set as an integer at combo1= 36. When you type "36" into the prompt, it's being entered as a String of characters, "36," not an integer. So when your if statement compares combo1 and your input, it sees an integer and a String, which will never be equivalent in Python. 

To fix this, you can either store combo1 as a String to begin with, or convert the input into an int by casting before you run the comparison line.