You already know how to use functions, why not write functions to clear/close and call them from your if/else?
like this:
like this:
def main(): *your calculator code* if something: clear() else: close() def clear(): print(" ") main() def close(): exit() main()