Engineer-Areeb's picture
Update app.py
7ba8e04 verified
import streamlit as st
st.set_page_config(page_title="Scientific Calculator", layout="centered")
st.title("๐Ÿงฎ Scientific Calculator")
# Input expression
expression = st.text_input("Enter a mathematical expression (e.g., 2*(3+4)/sin(45)):")
# Instructions
with st.expander("๐Ÿ“˜ Instructions"):
st.markdown("""
You can use the following operations and functions:
- There shouldn't be any blank space as well
- Basic arithmetic: `+`, `-`, `*`, `/`, `**` (power)
- Trigonometric: `sin(x)`, `cos(x)`, `tan(x)` (in degrees)
- Logarithms: `log(x)` (natural), `log10(x)`
- Square root: `sqrt(x)`
- Constants: `pi`, `e`
""")
# Evaluator
import math
import numpy as np
safe_dict = {
"sin": lambda x: math.sin(math.radians(x)),
"cos": lambda x: math.cos(math.radians(x)),
"tan": lambda x: math.tan(math.radians(x)),
"sqrt": math.sqrt,
"log": math.log,
"log10": math.log10,
"pi": math.pi,
"e": math.e,
"__builtins__": {}
}
if expression:
try:
result = eval(expression, {"__builtins__": {}}, safe_dict)
st.success(f"Result: `{result}`")
except Exception as e:
st.error(f"Error: {e}")