Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
11-liner: suppress SyntaxError for eval solution in Clear category for Safe Code by przemyslaw.daniel
def safe_code(equation):
from contextlib import suppress
equation = equation.replace('=', '==')
starting_value = '##' in equation
for value in map(str, range(starting_value, 10)):
if value in equation:
continue
with suppress(SyntaxError):
if eval(equation.replace('#', value)):
return int(value)
return -1
Sept. 17, 2018
Comments: