(Nov-21-2017, 02:49 AM)Austin11 Wrote: Ok so I redid my code(with the help of my teacher) and now I am running into the problem with validating the user input. Everything works great if they input a float number. yet if they input a string or space I get this error. I have a feeling that my code is stepping on each other somewhere but I can't find it. I don't want to convert the string, just error out nicely. Under the error is my updated code.
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: # 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