0

How to get the data type of an input of the form 'x + y' or 'x - y'?

If x or y is not a number, then it should print a message "Enter equation again". If the operator is not '+' or '-' it should print "Enter equation again" But, input() always reads an input as a string. So, how to compare the data type of 'x' and 'y'?

26th Oct 2021, 4:42 PM
Neethu Nath
Neethu Nath - avatar
2 Answers
+ 3
Use split() function and check each single item of input. Pseudo-Code: term = input().split() term[0] = number? term[1] = + or -? term[2] = number? And you do not need data type for x and y. There are string methods to check if it is a letter or a number.
26th Oct 2021, 5:09 PM
Coding Cat
Coding Cat - avatar
0
So should the printing be all this listed or just compare
26th Oct 2021, 4:56 PM
Chigozie Anyaeji 🇳🇬
Chigozie Anyaeji 🇳🇬 - avatar