Given an input A , print the data type of the input A.
eg:-Sequence of digits -- int
      Sequence of digits with a dot -- float
      Sequence of chars  -- string
      Single non-digit char --- char
 
Example 1:
Input: A = "12"
Output: "int"
Explanation: The input consists only of
digits.
Example 2:
Input: A = "gfg"
Output: "string"
Explanation: The input consists only of
characters.
 
Your Task:
You don't need to read or print anything. Your task is to complete the function FindInputType() which takes A as input parameter and returns data type of A.
 
Expected Time Complexity: O(|A|)
Expected Space Complexity: O(1)
 
Constraints:
1 <= |A| <= 1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
	def FindInputType(self, str):
		# Code here

Solutions:
class Solution:

	def FindInputType(self, str):
		if str.isdigit():
			return 'int'
		if '.' in str:
			p = str.split('.')
			if p[-1].isdigit() and p[-2].isdigit() and (len(p) == 2) or (p[-1].isdigit() and p[-2] == '' and (len(p) == 2)):
				return 'float'
			elif len(str) > 1:
				return 'string'
		if len(str) == 1:
			return 'char'
		elif len(str) > 1:
			return 'string'


class Solution:

	def FindInputType(self, str):
		s = str
		ans = 'string'
		if len(s) == 1:
			if s.isalpha() or s.__contains__('.'):
				ans = 'char'
			else:
				ans = 'int'
		elif s.count('.') == 1:
			try:
				s1 = s.split('.')
				if len(s1[1]) != 0:
					s = float(s)
					ans = 'float'
			except:
				ans = 'string'
		else:
			try:
				s1 = int(s)
				ans = 'int'
			except:
				ans = 'string'
		return ans


class Solution:

	def FindInputType(self, str):
		size = len(str)
		ans = ''
		(flag, init) = (0, 0)
		for i in range(size):
			if str[i] != '.' and str[i] > '9' or (str[i] != '.' and str[i] < '0'):
				init = 1
			if str[i] == '.':
				flag += 1
		if str[size - 1] == '.' and size != 1:
			ans = 'string'
		elif init == 0 and flag == 1 and (size > 1):
			ans = 'float'
		elif init == 0 and flag == 0:
			ans = 'int'
		elif size == 1:
			ans = 'char'
		else:
			ans = 'string'
		return ans


class Solution:

	def FindInputType(self, str):
		if len(str) == 1:
			if str.isnumeric():
				return 'int'
			return 'char'
		for i in str:
			if i.isalpha():
				return 'string'
		else:
			if '.' in str:
				a = str.split('.')
				if len(a) == 2 and len(a[1]) > 0 and (len(a[0]) >= 0):
					return 'float'
			else:
				return 'int'
		return 'string'