Apr-10-2019, 11:04 AM
(Apr-09-2019, 07:58 PM)ichabod801 Wrote: You are converting on line 4, you want that in the try block. An error on either one will trigger the except part, so you just need one of those. You also need a break statement.
try: val1, val2 = [int(x) for x in input("Please enter two numbers: ").replace(",", " ").split()] break except ValueError: print('Please enter valid numbers.')If the error happens on the second line, it will skip to the except. If it doesn't happen (valid input), it will break out of the loop.
That worked perfectly! I forgot that the input line actually tries to convert to integer so checks it already! Thanks for your help! much up votes :)