Shahabmoin commited on
Commit
22523d9
·
verified ·
1 Parent(s): 8eae373

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py CHANGED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import math
3
+
4
+ # Function to perform mathematical operations
5
+ def calculate(expression):
6
+ try:
7
+ # Evaluate the mathematical expression safely
8
+ result = eval(expression)
9
+ return result
10
+ except Exception as e:
11
+ return f"Error: {str(e)}"
12
+
13
+ # Streamlit App UI
14
+ st.title("Scientific Calculator")
15
+
16
+ # Input for the mathematical expression
17
+ expression = st.text_input("Enter a mathematical expression", "")
18
+
19
+ # Create buttons below the input field for mathematical operations
20
+ col1, col2, col3 = st.columns(3)
21
+
22
+ with col1:
23
+ if st.button('sin(x)'):
24
+ expression += 'sin('
25
+ with col2:
26
+ if st.button('cos(x)'):
27
+ expression += 'cos('
28
+ with col3:
29
+ if st.button('tan(x)'):
30
+ expression += 'tan('
31
+
32
+ col4, col5, col6 = st.columns(3)
33
+
34
+ with col4:
35
+ if st.button('log(x)'):
36
+ expression += 'log('
37
+ with col5:
38
+ if st.button('sqrt(x)'):
39
+ expression += 'sqrt('
40
+ with col6:
41
+ if st.button('exp(x)'):
42
+ expression += 'exp('
43
+
44
+ col7, col8 = st.columns(2)
45
+
46
+ with col7:
47
+ if st.button('pi'):
48
+ expression += 'math.pi'
49
+ with col8:
50
+ if st.button('e'):
51
+ expression += 'math.e'
52
+
53
+ # Display the updated expression in the text box
54
+ st.text_input("Enter a mathematical expression", expression)
55
+
56
+ # Operations
57
+ if expression:
58
+ result = calculate(expression)
59
+ st.write(f"Result: {result}")