Skip to content

simple and yet overly complicated calculator program written in python

Notifications You must be signed in to change notification settings

Squibid/python-calculator-colorized

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

python-calculator

simple and yet overly complicated calculator program written in python. I might improve it later.

import sys
import os
class Color:
   BLUE = '\033[94m'
   GREEN = '\033[92m'
   RED = '\033[91m'
   BOLD = '\033[1m'
   END = '\033[0m'
clearConsole = lambda: os.system('cls' if os.name in ('nt', 'dos') else 'clear')

while True:
   calc = input(Color.BLUE + Color.BOLD + "Type calculation" + Color.END + ": ")
   if 'clear' in calc:
      clearConsole()
   if 'exit' in calc:
      sys.exit()
   if 'clear' not in calc:
      try:
         print(Color.GREEN + Color.BOLD + "Answer" + Color.END + ": " + str(eval(calc)) + "\n")
         ans=int(eval(calc))
      except Exception as error:
         if 'ans' in str(error):
            print(Color.RED + Color.BOLD + "You can not use the previous answer as currently there is not one!\n" + Color.END)
         else:
            print(Color.RED + Color.BOLD + "looks like something went wrong: " + Color.END + str(error) + Color.RED + Color.BOLD + "!\n" + Color.END)  

About

simple and yet overly complicated calculator program written in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages