import math
print "python calculator"
print "calc or eval"
while 0 == 0:
check = raw_input() #(experimental evaluation or traditional calculator)
if check == "eval":
a = raw_input("operator\n") #operator
if a == "+":
b = input("arg1\n") #inarg1
c = input("arg2\n") #inarg2
z = b + c
print z
elif a == "-":
b = input("arg1\n") #inarg1
c = input("arg2") #inarg2
z = b - c
print z
elif a == "/":
b = input("arg1\n") #inarg1
c = input("arg2\n") #inarg2
z = b / c
print z
elif a == "*":
b = input("arg1\n") #inarg1
c = input("arg2]n") #inarg2
z = b * c
print z
elif a == "^":
b = input("arg1\n") #inarg1
c = input("arg2\n") #inarg2
z = b ** c
elif a == "sin":
b = input("arg1\n") #inarg1
var = math.degrees(math.sin(b))
print var
elif a == "asin":
b = input("arg1\n") #inarg1
var = math.degrees(math.asin(b))
print var
elif a == "cos":
b = input("arg1\n") #inarg1
var = math.degrees(math.cos(b))
print var
elif a == "acos":
b = input("arg1\n") #inarg1
var = math.degrees(math.acos(b))
print var
elif a == "tan":
b = input("arg1\n") #inarg1
var = math.degrees(math.tan(b))
print var
elif a == "atan":
b = input("arg1\n") #inarg1
var = math.degrees(math.atan(b))
print var
elif check == "calc" :
x = input() #takes input as expression
print x #prints expression's result
Isn't the sine of 90 degrees 1? With this it shows up as something around 51.2? Google's calculator does this too? BTW: this is my python calculator
b = input("arg1\n") #inarg1
var = math.degrees(math.sin(b))
print var
This one and other trig functions are the problem. For the most part, this was just a simple python calculator, but I wanted to add some trig functions.
You don't want o convert the return value of sin()
to degrees -- the return value isn't an angle. You instead want to convert the argument to radians, since math.sin()
expects radians:
>>> math.sin(math.radians(90))
1.0
Python's sin and cos take radians not degrees. You can convert using the math.radians function. Basically, you are using the wrong units.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With