File size: 1,367 Bytes
22523d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea48bb6
22523d9
 
 
 
 
ea48bb6
 
22523d9
ea48bb6
 
22523d9
ea48bb6
 
22523d9
 
 
 
ea48bb6
 
22523d9
ea48bb6
 
22523d9
ea48bb6
 
22523d9
 
 
 
ea48bb6
22523d9
 
ea48bb6
22523d9
 
 
ea48bb6
22523d9
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
import math

# Function to perform mathematical operations
def calculate(expression):
    try:
        # Evaluate the mathematical expression safely
        result = eval(expression)
        return result
    except Exception as e:
        return f"Error: {str(e)}"

# Streamlit App UI
st.title("Scientific Calculator")

# Input for the mathematical expression
expression = st.text_input("Enter a mathematical expression", "")

# Create buttons below the input field for mathematical operations
col1, col2, col3 = st.columns(3)

with col1:
    if st.button('sin(x)'):
        expression += 'sin('
with col2:
    if st.button('cos(x)'):
        expression += 'cos('
with col3:
    if st.button('tan(x)'):
        expression += 'tan('

col4, col5, col6 = st.columns(3)

with col4:
    if st.button('log(x)'):
        expression += 'log('
with col5:
    if st.button('sqrt(x)'):
        expression += 'sqrt('
with col6:
    if st.button('exp(x)'):
        expression += 'exp('

col7, col8 = st.columns(2)

with col7:
    if st.button('pi'):
        expression += 'math.pi'
with col8:
    if st.button('e'):
        expression += 'math.e'

# Display the updated expression in the text box
st.text_input("Enter a mathematical expression", expression)

# Operations
if expression:
    result = calculate(expression)
    st.write(f"Result: {result}")