Skip to content

Commit

Permalink
update calculator.py
Browse files Browse the repository at this point in the history
added log functions to the calculator

Signed-off-by: AKSHAYA MADHURI <76612327+akshaya-hub@users.noreply.github.com>
  • Loading branch information
akshayamadhuri committed Feb 9, 2023
1 parent 177b7dc commit 05a2b79
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions 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()

0 comments on commit 05a2b79

Please sign in to comment.