Recently I found a method of testing whether or not a variable is an int or not in Python 3. It's syntax is like this:
try:
a = int(a)
except ValueError:
print("Watch out! The Index is not a number :o (this probably won't break much in this version, might in later ones though!")
error = True
However, when testing multiple variables it quickly becomes horrible to look at:
def IntegerChecker(a, b, c, d): #A is Index, B is End Time, C is Distance, D is Speed Limit
global error
try:
a = int(a)
except ValueError:
print("Watch out! The Index is not a number :o (this probably won't break much in this version, might in later ones though!")
error = True
try:
b = int(b)
except ValueError:
print("Watch out! The End Time is not a number :o")
error = True
try:
c = int(c)
except ValueError:
print("Watch out! The Distance is not a number :o")
error = True
try:
d = int(d)
except ValueError:
print("Watch out! The Speed Limit is not a number :o")
error = True
Is there not an easier way to test whether a variable is an integer or not, and if it is not then change a variable to true and print a unique message to the user?
Please be aware that I am a more novice programmer in Python, however if there is a more complicated method to doing this which concise I would love to know. On another note, would this be better in the code review section of Stack Exchange?