Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import commands
- import math
- print """
- Welcome to the calculator! This is really poorly-made; please forgive that.
- If everything is up and running (I put in about an hour or two into testing to
- make sure), it can perform log(x) functions, elementary trig functions and their
- reciprocals (please put in degrees, as I put in radian conversion for the sake
- of dedicating the command to memory without bruteforcing it ;-;), powers,
- commonly known constants (pi -> p, e), and of course basic arithmetic.
- Seeing as this is written in python, it's not really that impressive. Sorry
- about that. Anywho, the calculator is your typical desktop calculator.
- log_e(x) = ln(x)
- Do the following: For the product of 3 * 4...
- *
- 3
- 4
- [comp] --------
- [comp] 12
- To include an answer, type 'ans' without the quotes.
- add sub mul div log exp exit
- sin cos tan csc sec cot cls
- formatted to six decimal places
- um... If you need to get ahold of me for criticism or whatnot,
- init.jon@yahoo.com .
- """
- answer = 0.0
- command = ''
- # basically a shitload of command checks
- while command != 'x' and command != 'exit':
- arg1 = 0.0
- arg2 = 0.0
- arg = 0.0
- command = raw_input("Command: ")
- if 'add' in command or '+' in command:
- arg1, arg2 = '~', '~'
- while arg1 == '~' or arg2 == '~':
- arg1 = raw_input("Arg1: ")
- if arg1 == 'ans':
- arg1 = ans
- elif 'e' in arg1:
- arg1 = commands.euler()
- elif 'p' in arg1:
- arg1 = commands.pi()
- elif not float(arg1):
- print "bad arg"
- arg1 = '~'
- if not arg1 == '~':
- arg2 = raw_input("Arg2: ")
- if arg2 == 'ans':
- arg2 = ans
- elif 'e' in arg2:
- arg2 = commands.euler()
- elif 'p' in arg2:
- arg2 = commands.pi()
- elif not float(arg2):
- print "bad arg"
- arg1 = '~'
- if not arg2 == '~':
- ans = commands.plus(float(arg1),float(arg2))
- elif 'sub' in command or '-' in command:
- arg1, arg2 = '~', '~'
- while arg1 == '~' or arg2 == '~':
- arg1 = raw_input("Arg1: ")
- if arg1 == 'ans':
- arg1 = ans
- elif 'e' in arg1:
- arg1 = commands.euler()
- elif 'p' in arg1:
- arg1 = commands.pi()
- elif not float(arg1):
- print "bad arg"
- arg1 = '~'
- if not arg1 == '~':
- arg2 = raw_input("Arg2: ")
- if arg2 == 'ans':
- arg2 = ans
- elif 'e' in arg2:
- arg2 = commands.euler()
- elif 'p' in arg2:
- arg2 = commands.pi()
- elif not float(arg2):
- print "bad arg"
- arg1 = '~'
- if not arg2 == '~':
- ans = commands.minus(float(arg1),float(arg2))
- elif 'mul' in command or '*' in command:
- arg1, arg2 = '~', '~'
- while arg1 == '~' or arg2 == '~':
- arg1 = raw_input("Arg1: ")
- if arg1 == 'ans':
- arg1 = ans
- elif 'e' in arg1:
- arg1 = commands.euler()
- elif 'p' in arg1:
- arg1 = commands.pi()
- elif not float(arg1):
- print "bad arg"
- arg1 = '~'
- if not arg1 == '~':
- arg2 = raw_input("Arg2: ")
- if arg2 == 'ans':
- arg2 = ans
- elif 'e' in arg2:
- arg2 = commands.euler()
- elif 'p' in arg2:
- arg2 = commands.pi()
- elif not float(arg2):
- print "bad arg"
- arg1 = '~'
- if not arg2 == '~':
- ans = commands.times(float(arg1),float(arg2))
- elif 'div' in command or '/' in command:
- arg1, arg2 = '~', '~'
- while arg1 == '~' or arg2 == '~':
- arg1 = raw_input("Numerator: ")
- if arg1 == 'ans':
- arg1 = ans
- elif 'e' in arg1:
- arg1 = commands.euler()
- elif 'p' in arg1:
- arg1 = commands.pi()
- elif not float(arg1):
- print "bad arg"
- arg1 = '~'
- if not arg1 == '~':
- arg2 = raw_input("Denominator: ")
- if arg2 == 'ans':
- arg2 = ans
- elif 'e' in arg2:
- arg2 = commands.euler()
- elif 'p' in arg2:
- arg2 = commands.pi()
- elif not float(arg2):
- print "bad arg"
- arg1 = '~'
- if not arg2 == '~':
- ans = commands.div(float(arg1),float(arg2))
- elif 'exp' in command or '^' in command:
- arg1, arg2 = '~', '~'
- while arg1 == '~' or arg2 == '~':
- arg1 = raw_input("Base: ")
- if arg1 == 'ans':
- arg1 = ans
- elif 'e' in arg1:
- arg1 = commands.euler()
- elif 'p' in arg1:
- arg1 = commands.pi()
- elif not float(arg1):
- print "bad arg"
- arg1 = '~'
- if not arg1 == '~':
- arg2 = raw_input("Exponent: ")
- if arg2 == 'ans':
- arg2 = ans
- elif 'e' in arg2:
- arg2 = commands.euler()
- elif 'p' in arg2:
- arg2 = commands.pi()
- elif not float(arg2):
- print "bad arg"
- arg1 = '~'
- if not arg2 == '~':
- ans = commands.exponential(float(arg1),float(arg2))
- elif 'log' in command:
- arg1, arg2 = '~', '~'
- while arg1 == '~' or arg2 == '~':
- arg1 = raw_input("Log base: ")
- if arg1 == 'ans':
- arg1 = ans
- elif 'e' in arg1:
- arg1 = commands.euler()
- elif 'p' in arg1:
- arg1 = commands.pi()
- elif not float(arg1):
- print "bad arg"
- arg1 = '~'
- if not arg1 == '~':
- arg2 = raw_input("Of? ")
- if arg2 == 'ans':
- arg2 = ans
- elif 'e' in arg2:
- arg2 = commands.euler()
- elif 'p' in arg2:
- arg2 = commands.pi()
- elif not float(arg2):
- print "bad arg"
- arg1 = '~'
- if not arg2 == '~':
- ans = math.log(float(arg1),float(arg2))
- elif 'sin' in command:
- arg = '~'
- while arg == '~':
- arg = raw_input("Argument (Degrees): ")
- if 'ans' in arg:
- arg = ans
- elif 'e' in arg:
- arg = commands.euler()
- elif 'p' in arg:
- arg = commands.pi()
- elif not float(arg):
- print 'bad arg'
- arg = '~'
- if not arg == '~':
- ans = math.sin(math.radians(float(arg)))
- elif 'cos' in command:
- arg = '~'
- while arg == '~':
- arg = raw_input("Argument (Degrees): ")
- if 'ans' in arg:
- arg = ans
- elif 'e' in arg:
- arg = commands.euler()
- elif 'p' in arg:
- arg = commands.pi()
- elif not float(arg):
- print 'bad arg'
- arg = '~'
- if not arg == '~':
- ans = math.cos(math.radians(float(arg)))
- elif 'tan' in command:
- arg = '~'
- while arg == '~':
- arg = raw_input("Argument (Degrees): ")
- if 'ans' in arg:
- arg = ans
- elif 'e' in arg:
- arg = commands.euler()
- elif 'p' in arg:
- arg = commands.pi()
- elif not float(arg):
- print 'bad arg'
- arg = '~'
- if not arg == '~':
- ans = math.tan(math.radians(float(arg)))
- elif 'csc' in command:
- arg = '~'
- while arg == '~':
- arg = raw_input("Argument (Degrees): ")
- if 'ans' in arg:
- arg = ans
- elif 'e' in arg:
- arg = commands.euler()
- elif 'p' in arg:
- arg = commands.pi()
- elif not float(arg):
- print 'bad arg'
- arg = '~'
- if not arg == '~':
- ans = 1 / math.sin(math.radians(float(arg)))
- elif 'sec' in command:
- arg = '~'
- while arg == '~':
- arg = raw_input("Argument (Degrees): ")
- if 'ans' in arg:
- arg = ans
- elif 'e' in arg:
- arg = commands.euler()
- elif 'p' in arg:
- arg = commands.pi()
- elif not float(arg):
- print 'bad arg'
- arg = '~'
- if not arg == '~':
- ans = 1 / math.cos(math.radians(float(arg)))
- elif 'cot' in command:
- arg = '~'
- while arg == '~':
- arg = raw_input("Argument (Degrees): ")
- if 'ans' in arg:
- arg = ans
- elif 'e' in arg:
- arg = commands.euler()
- elif 'p' in arg:
- arg = commands.pi()
- elif not float(arg):
- print 'bad arg'
- arg = '~'
- if not arg == '~':
- ans = 1 / math.tan(math.radians(float(arg)))
- elif 'x' in command or 'exit' in command:
- print "Goodbye!"
- elif 'cls' in command or 'clear' in command:
- answer = 0.0
- else:
- print "I don't believe that I understood that."
- print "------------"
- commands.scientific_notation(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement