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")
2
  • 3
    Input is a string, you need to convert it. Commented Jul 29, 2018 at 10:58
  • 1
    input will always return a str. What, exactly, are you trying to do here? Commented Jul 29, 2018 at 11:01

1 Answer 1

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 )
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.