r/pythonhelp • u/PracticalTale6528 • Mar 31 '22
HOMEWORK Condensing try except block
Is there a way to condense these into one block? They do the same thing and I'm trying to learn how to condense them.
try:
try:
b = int(b2)
except ValueError as e:
raise InvalidInput(str(e))
try:
g = int(g2)
except ValueError as e:
raise InvalidInput(str(e))
s = (int(g2)) - int(b2) / 2
except InvalidInput as e:
return str(e), 400
2
Upvotes
1
u/PracticalTale6528 Mar 31 '22
How do you mean?