File size: 1,550 Bytes
400b6ca
43148d3
 
0e0a10a
400b6ca
 
0e0a10a
400b6ca
 
0e0a10a
400b6ca
 
 
0e0a10a
400b6ca
 
 
 
 
0e0a10a
400b6ca
 
 
 
 
 
 
 
 
 
 
0e0a10a
400b6ca
 
 
 
 
 
 
 
 
 
43148d3
400b6ca
 
 
 
0e0a10a
400b6ca
 
 
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
import streamlit as st
import math


st.title("Scientific Calculator")


st.sidebar.header("Select Operation")


num1 = st.number_input("Enter first number", value=0.0)
num2 = st.number_input("Enter second number", value=0.0)


operation = st.sidebar.selectbox(
    "Select Operation",
    ("Add", "Subtract", "Multiply", "Divide", "Sin", "Cos", "Tan", "Log", "Sqrt", "Exp")
)


def scientific_calculator(num1, num2, operation):
    try:
        if operation == "Add":
            return num1 + num2
        elif operation == "Subtract":
            return num1 - num2
        elif operation == "Multiply":
            return num1 * num2
        elif operation == "Divide":
            return num1 / num2 if num2 != 0 else "Error: Division by zero"
        elif operation == "Sin":
            return math.sin(math.radians(num1))  
        elif operation == "Cos":
            return math.cos(math.radians(num1))
        elif operation == "Tan":
            return math.tan(math.radians(num1))
        elif operation == "Log":
            return math.log(num1) if num1 > 0 else "Error: Log of non-positive number"
        elif operation == "Sqrt":
            return math.sqrt(num1) if num1 >= 0 else "Error: Negative input for square root"
        elif operation == "Exp":
            return math.exp(num1)
        else:
            return "Invalid operation"
    except Exception as e:
        return f"Error: {e}"


if st.sidebar.button("Calculate"):
    result = scientific_calculator(num1, num2, operation)
    st.write(f"**Result:** {result}")