(Nov-21-2017, 04:09 AM)Austin11 Wrote:(Nov-21-2017, 03:28 AM)Prrz Wrote: Hello there! What you are looking for is the ValueError exception. I believe a good way to implement this would be as follows:
def a_function(): # A Function try: while not done: # Code is being executed except ValueError: # Except when code raises a ValueError print("That's not a number!") # Optional return a_function() # Then return a_function()Think about where in your code this may be implemented best!
For more information on Errors and Exceptions, refer to the following python documentation:
https://docs.python.org/3/tutorial/errors.html
Regards,
Prrz
Ok, quick question on this. Are you saying I should add a new function in order to satisfy the ValueError or clean up one of my validating functions? Just trying to clarify things so I understand better.
Thanks!
I'm suggesting cleaning up an existing function that is already written. I tried to format the example I made to mimic one that already exists in your code, perhaps I should have been more clear.
I did not want to simply solve it for you, but if you do get stuck I will gladly help. I added a small snippet from the example I posted in this post, that should also add clarity to my suggestion.
ps. I know you raised a ValueError exception at the beginning of your code, you had the right idea,
but think about how this may not work as intended. Hopefully, that clears up some confusion.
For the sake of not re-writing your code, this is all you need in this function.
def valid_float_number(value): float(value) return True