Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
could 12 lines proc be clear? solution in Clear category for Calculator-II by CDG.Axel
def calculator(log: str) -> str:
second, screen, new, op, magic = 0, 0, True, '=', lambda: (screen, -screen)[op == '-']
for key in log:
if key.isdigit():
screen = screen * 10 * (not new) + int(key)
elif key in '+-':
second = screen = screen if op == '=' or new else second + magic()
elif key == '=' == op:
screen = screen + second
elif key == '=':
screen = (second, screen)[new] + (second := magic())
op = (op, key)[new := key in '+-=']
return str(screen)
Feb. 10, 2023
Comments: