From 05a2b79f8ac65166631125b033ebee73321d707b Mon Sep 17 00:00:00 2001 From: AKSHAYA MADHURI <76612327+akshaya-hub@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:52:21 +0530 Subject: [PATCH] update calculator.py added log functions to the calculator Signed-off-by: AKSHAYA MADHURI <76612327+akshaya-hub@users.noreply.github.com> --- python/calculator.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/calculator.py b/python/calculator.py index ce08384d..1fcf538f 100644 --- a/python/calculator.py +++ b/python/calculator.py @@ -1,18 +1,22 @@ """Simple calculator app""" +import math def main(): while True: try: string = input("> ") - print(eval(string)) + parts = string.split(" ") + if len(parts) == 3 and parts[0] == "log": + print(math.log(int(parts[2]), int(parts[1]))) + else: + print(eval(string)) except (KeyboardInterrupt, EOFError): print() exit() - except (BaseException, KeyboardInterrupt) as e: + except Exception as e: print(e) - if __name__ == "__main__": print("Welcome to calculator!") main()