w3resource logo


Python Exercises

Python Exercise: Program to test whether an input is an integer


Write a Python program to test whether an input is an integer.

Sample Solution :

Python Code :

def is_integer(n):  
  try:
      n= int(n)
      print("valid integer :", n)
  except ValueError as err:
      print(err)
is_integer(15)
is_integer(5.65)
is_integer('5.65')

Console :

Copy and paste the above code and press "Enter key" to execute :

Post your code through Disqus