Engineer-Areeb commited on
Commit
f1c5dfd
·
verified ·
1 Parent(s): dff564c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.set_page_config(page_title="Scientific Calculator", layout="centered")
4
+
5
+ st.title("🧮 Scientific Calculator")
6
+
7
+ # Input expression
8
+ expression = st.text_input("Enter a mathematical expression (e.g., 2*(3+4) / sin(45)):")
9
+
10
+ # Instructions
11
+ with st.expander("📘 Instructions"):
12
+ st.markdown("""
13
+ You can use the following operations and functions:
14
+
15
+ - Basic arithmetic: `+`, `-`, `*`, `/`, `**` (power)
16
+ - Trigonometric: `sin(x)`, `cos(x)`, `tan(x)` (in degrees)
17
+ - Logarithms: `log(x)` (natural), `log10(x)`
18
+ - Square root: `sqrt(x)`
19
+ - Constants: `pi`, `e`
20
+ """)
21
+
22
+ # Evaluator
23
+ import math
24
+ import numpy as np
25
+
26
+ safe_dict = {
27
+ "sin": lambda x: math.sin(math.radians(x)),
28
+ "cos": lambda x: math.cos(math.radians(x)),
29
+ "tan": lambda x: math.tan(math.radians(x)),
30
+ "sqrt": math.sqrt,
31
+ "log": math.log,
32
+ "log10": math.log10,
33
+ "pi": math.pi,
34
+ "e": math.e,
35
+ "__builtins__": {}
36
+ }
37
+
38
+ if expression:
39
+ try:
40
+ result = eval(expression, {"__builtins__": {}}, safe_dict)
41
+ st.success(f"Result: `{result}`")
42
+ except Exception as e:
43
+ st.error(f"Error: {e}")