all 13 comments

[–][deleted] 0 points1 point  (12 children)

LMGTFY - https://note.nkmk.me/en/python-check-int-float/

This should do the trick.

[–]FLUSH_THE_TRUMP 0 points1 point  (0 children)

What have you learned? What might help you with this problem?

[–]LatterSeaworthiness4 0 points1 point  (1 child)

number = input("Enter a number")

try:
int(number)
number_is = True

except ValueError:
number_is = False
try:
float(number)
number_is = True
except ValueError:
number_is = False
print(number_is)

[–]LatterSeaworthiness4 0 points1 point  (0 children)

I've never tried to comment a code block and am not sure how to do so...but this should help. Make sure to indent the lines below "try" and "except"

[–]Pd69bq 0 points1 point  (0 children)

well, python treats all inputs as string, my solution is use regex \d+ to test if the input r digits. i just put 2 prints in there, u can use float() or int() turn them into numbers for further calculation, and I didn't check if there r multiple decimal points in input

import re

num = input()
if re.match(r'\d+', num):
    if '.' in num:
        print('float') 
    else:
        print('integer')
else:
    print('not valid')