Scientific Calculator using Python.
0 minute read
You can make a scientific calculator in python. Python uses NLP(Natural Language Processing) to perform basic calculations. But to perform calculations based on trigonometry, logarithm, you need to use a library named 'math'.
So, let's make a scientific calculator in python.
For more information about python programming, check out the below Instagram account
Here is the code for that:
import math as m
while True:
a = float(input("Enter number 1: "))
b = float(input("Enter number 2: "))
while True:
print(''' 1. Addition
2.Subtraction
3.Multiplication
4.Division
5.Sine
6.Cosine
7.Tangent
8.Logarithm''')
c = input(("Select operation: "))
print("The operation you have selected is: ", c)
d = input("Do you want to proceed with this operation?(y/n): ")
if(d=="y"):
break
if("1"==c or "Addition"==c):
print("Addition = ", a+b)
elif("2"==c or "Subtraction"==c):
print("Subtraction = ", a-b)
elif("3"==c or "Multiplication"==c):
print("Multiplication = ", a*b)
elif("4"==c or "Division"==c):
print("Division = ", a/b)
elif("5"==c or "Sine"==c):
print('sin', a, '=', m.sin(a))
elif('6'==c or 'Cosine'==c):
print('cos', a, '=', m.cos(a))
elif('7'==c or 'Tangent'==c):
print('tan', a, '=', m.tan(a))
elif('8'==c or 'Logarithm'==c):
e = input("Select base for logarithm: ", '(', a, '/', b, ')')
if(e=='a'):
print("logb to the base a: ", m.log(b,a))
elif(e=='b'):
print("loga to the base b: ", m.log(a,b))
else:
print("Error")
else:
print("Please select one of the above operations.")
Post a Comment