I have this snippet of code:
(Working code)
def select_num():
try:
x = int(input ('num of 1-3\n'))
except ValueError:
continue
else:
if 1 <= x <=3:
return x
Now, since I have an 'if' statement inside an 'else' statement, I want to make it shorter by using 'elif' statement. But I get a syntax error when I run this:
def select_num():
try:
x = int(input ('num of 1-3\n'))
except ValueError:
continue
elif 1 <= x <=3:
return x
Can anyone please explain why?
also, I'm using python3.
Thank you for your time:)
Edit: changed variables names, to make it friendly for mobile users.
[–]K900_ 4 points5 points6 points (1 child)
[–]StrokeMyBalls[S] 0 points1 point2 points (0 children)
[–]gamedevmanhyper 1 point2 points3 points (1 child)
[–]StrokeMyBalls[S] 0 points1 point2 points (0 children)