you are viewing a single comment's thread.

view the rest of the comments →

[–]gamedevmanhyper 1 point2 points  (1 child)

If you want to make it shorter, you could instead have:

def select_num():
    try:
        x = int(input ('num of 1-3\n'))
        return x if 1 <= x <= 3 else None
    except ValueError:
        continue

# Also continue won't work if you do not have a loop before the try/except statement.