Program to check if input is an integer or a string | This function Returns true if s is a number else false ; Driver code ; Store the input in a str variable ; Function returns 1 if all elements are in range '0 ▁ - ▁ 9' ; Function returns 0 if the input is not an integer
def isNumber ( s ) : NEW_LINE INDENT for i in range ( len ( s ) ) : NEW_LINE INDENT if s [ i ] . isdigit ( ) != True : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = "6790" NEW_LINE if isNumber ( str ) : NEW_LINE INDENT print ( " Integer " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " String " ) NEW_LINE DEDENT DEDENT