0

So i'm new to python, but used to code in Lua a lot. I'm having an issue with something basic that should be working but isn't.

def test():
    age = input("Enter Age:")

    if type(age) is int:
        print("Is integer.")
    else:
        print("Is not integer.")

test()

So basically, I run this, then I enter an integer, like "18". The expected output would be "Is integer", but for some reason, it isn't; it's "Is not integer."

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

In python every input is treated as string. If you want integers, you've to explicitly cast them like so

age = int(input("Enter Age:"))
Eeshaan
  • 1,557
  • 1
  • 10
  • 22