Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # - Get the input value
- x = input('Enter a number')
- # - Determine what it is. Try float first, because an int value
- # will also succeed.
- is_float = False
- try:
- check_float = float(x)
- # - If no error is raised, it's a float value
- is_float = True
- except ValueError:
- # - it can't be converted to an float
- pass
- # - Now try as an int
- is_int = False
- try:
- check_int = int(x)
- # - If no error is raised, it's an int value
- is_int = True
- except ValueError:
- # - it can't be converted to an int
- pass
- # - Display results as needed. Note that is_int AND is_float
- # might both be false!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement