0

The input is symbol or number

function or method for finding out whether the input from the string is symbol on number in Python3 for example s = input("some string") # s = "5+6*/" need such a result 5 Number + Symbol(or something like that) 6 Number * Symbol / Symbol

18th Mar 2018, 9:52 AM
Ani Naslyan
Ani Naslyan - avatar
3 Answers
18th Mar 2018, 10:24 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 4
So, take the string, break it apart, and try and cast each one to an int? I'm not sure if this would work in python or not.
18th Mar 2018, 10:12 AM
J.G.
J.G. - avatar
+ 2
a = input() for x in a: try: print(int(x)*''+str(x)+' is a number') except ValueError: print(x, 'is a literal')
18th Mar 2018, 11:16 AM
strawdog
strawdog - avatar