File size: 1,190 Bytes
f1c5dfd
 
 
 
 
 
 
7ba8e04
f1c5dfd
 
 
 
 
 
7ba8e04
f1c5dfd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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}")