testing - Checking Multiple Integers in Python 3 -


Recently I have found a method to test whether a variable is an integer or not in Python 3. This syntax is like this:

  Try: a = int (a) Excluding ValueError: Print ("See" Index is not a number: o (It probably does not break much in this version However, people who are after! ") Error = true  

However, when many variables are tested, it quickly becomes horrible:

  def integerChecker (a, b, c, d): # is an index, b is the end time, c is the distance, try the speed limit global error: a = int (a) ValueError: pri Nt ("See out! Index number is not: o (This will probably not break much in this version, maybe later in the!!)) Error = try the truth: b = int (b) ValueError: print (Try out "end time is not a number: o") try error = true: c = int (c) except valueError: print ("look! Distance is not a number: o") error = try the truth : D = int (d) except ValueError: print ("see, speed limit is not a number: o") error = the source Yes  

It is not an easy way to check whether the variable is an integer, and if it does not, then a variable actually changes and prints a unique message to the user. ?

Please keep in mind that I am a newbie programmer in Python, but if there is another complicated method to do this I would like to know briefly. On another note, would it be better in the Code Review section of the Stack Exchange?

This is my solution

  def IntegerChecker (** kwargs) : # Is an index, b is end time, c is distance, d speed limit is error = false error = {'index': ('see index number is not: o (this probably won' 'in this version There is a number: o ',' distance ':' look! Distance is no number: o ',' Speed ​​':' Watch out! Speed ​​limit is not a number: O '} for key, kwargs.items () in value: try: int (value) except valueError: print (err.get (key)) error = True return error IntegerChecker (index = a, end_time = b, Distance = c, speed = d)  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -