0

I am brand new to Python!

If I run the following code on Python 2.7 by giving the input as 7 then it executes the If statement correctly (Expected Results).

However, If I run it using PyCharm or other editor which is using Python 3.6 binaries, then it always executes the else statement with the input of 7

print("Welcome to Guess the Number Game!")
userNumber = input("Enter the Number between 1 and 20: ")
randomNumber = 7
if (userNumber == randomNumber):
    print("You got it!")
else:
    print("Try again!")
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    Yes, because the `input` in python 2.7 actually does some kind of "eval" on what you provide, and will actually give you an `int` type. However, whatever you input in python 3.x will give you a string, which is similar to how `raw_input` works in python2.7. So, your solution will have to be to actually explicitly cast it to an `int`. -> `int(input("Enter the Number between 1 and 20: "))` – idjaw Jun 12 '17 at 02:27
  • Thanks idjaw, that fixed my issue! – Vignesh Nadar Jun 12 '17 at 02:32

0 Answers0