Value Type Finder
Python
Easy
6 views
Problem Description
Read one token. Decide its data type using simple rules: True/False is BOOL, signed digits is INT, number with dot is FLOAT, otherwise STRING. Output the type name.
Input Format
One token (no spaces).
Output Format
One word: BOOL/INT/FLOAT/STRING.
Official Solution
import sys,re
s=sys.stdin.read().strip()
if not s: sys.exit(0)
if s=='True' or s=='False':
sys.stdout.write('BOOL')
elif re.fullmatch(r'[+-]?\\d+',s):
sys.stdout.write('INT')
elif re.fullmatch(r'[+-]?(?:\\d+\\.\\d*|\\d*\\.\\d+)',s):
sys.stdout.write('FLOAT')
else:
sys.stdout.write('STRING')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!