0

As part of a lcm program I'm creating, I want a condition to determine whether the result of an expression is integer or float. After looking online, I found the isinstance function, which outputs a boolean. I want to be able to use that in the statement, and execute the respective . How exactly do I code it? This is an example:

num=input("Enter a number: ")
if isinstance(num,int):
  print("Float")
else:
  print("Integer")
ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57
Fluid Sphere
  • 13
  • 1
  • 3

1 Answers1

2

You need to go deeper =)

def int_of_float( n ) :
    try :
        num = int(num)
        return 'Integer'
    except ValueError :
        pass

    try :
        num = float(num)
        return 'Float'
    except ValueError :
        pass

    return 'Unknown'

num = input( 'need a number: ' )
print int_or_float( num )
lenik
  • 23,228
  • 4
  • 34
  • 43