Apr-09-2019, 12:08 PM
There are a number of ways you can deal with this. You could do two separate inputs to get the different numbers. You could be explicit about needing a space. You could replace other common delimiters with spaces before splitting (
If you want to give multiple chances to correct the input, a while True loop is often used:
input('Enter two numbers: ').replace(',', ' ').split()
). You could write a regular expression matching valid numbers, and use findall to get a list of valid numbers in the input.If you want to give multiple chances to correct the input, a while True loop is often used:
while True: values = input('Enter two numbers: ') try: # to convert to integer except ValueError: print('Invalid input') else: breakInstead of (or in addition to) the try/except block, you might check for a valid range or other issues with if/else, again breaking if the input is valid.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures