+ 1
Is there an easy way to find the datatype of a given variable entered by user?
Problem solving
5 Antworten
+ 3
In Python it is easy: input is always string, so if you want something else, you need to convert that string.
It comes down to if the string even contains something convertible: if you try int('hello'), you will get an error.
Like Muhd Khairul Amirin Bin Yaacob said, you can use exception handling:
data = input()
try:
data = float(data)
except:
print('Enter a NUMBER I said!')
So when float leads to an error, the except-branch will be executed.
+ 1
You can use exception handling
+ 1
But c doesn't have exception handlers
+ 1
Yeah in C it's all messier... :) Just trying to get a handle of that myself right now.