Spaces:
No application file
No application file
Create scientificcalculator.py
Browse files- scientificcalculator.py +25 -0
scientificcalculator.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
+
|
| 4 |
+
# Set the title for the app
|
| 5 |
+
st.title("Scientific Calculator")
|
| 6 |
+
|
| 7 |
+
# Input box for the user to enter the expression
|
| 8 |
+
expression = st.text_input("Enter the mathematical expression:")
|
| 9 |
+
|
| 10 |
+
# Available scientific functions
|
| 11 |
+
def calculate(expression):
|
| 12 |
+
try:
|
| 13 |
+
# Evaluate the expression for basic arithmetic operations
|
| 14 |
+
result = eval(expression, {"__builtins__": None}, {
|
| 15 |
+
'sin': math.sin, 'cos': math.cos, 'tan': math.tan,
|
| 16 |
+
'sqrt': math.sqrt, 'exp': math.exp, 'log': math.log,
|
| 17 |
+
'pi': math.pi, 'e': math.e, 'log10': math.log10
|
| 18 |
+
})
|
| 19 |
+
return result
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return "Error: " + str(e)
|
| 22 |
+
|
| 23 |
+
if expression:
|
| 24 |
+
result = calculate(expression)
|
| 25 |
+
st.write(f"Result: {result}")
|