File size: 2,230 Bytes
f3245c5
a363591
 
f3245c5
a363591
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3245c5
a363591
 
 
 
 
 
f3245c5
a363591
 
 
 
f3245c5
a363591
 
 
f3245c5
a363591
 
f3245c5
a363591
 
f3245c5
a363591
 
f3245c5
 
a363591
 
 
 
 
f3245c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import streamlit as st
import math

# Define functions for various scientific operations
def add(x, y):
    return x + y

def subtract(x, y):
    return x - y

def multiply(x, y):
    return x * y

def divide(x, y):
    if y == 0:
        return "Cannot divide by zero"
    return x / y

def power(x, y):
    return math.pow(x, y)

def sqrt(x):
    return math.sqrt(x)

def log10(x):
    if x <= 0:
        return "Logarithm undefined for non-positive numbers"
    return math.log10(x)

def loge(x):
    if x <= 0:
        return "Natural log undefined for non-positive numbers"
    return math.log(x)

def sine(x):
    return math.sin(math.radians(x))

def cosine(x):
    return math.cos(math.radians(x))

def tangent(x):
    return math.tan(math.radians(x))

def factorial(x):
    if x < 0:
        return "Factorial undefined for negative numbers"
    return math.factorial(int(x))

def absolute(x):
    return abs(x)

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

# Input fields for two numbers (for binary operations)
num1 = st.number_input("Enter the first number:", value=0.0)
num2 = st.number_input("Enter the second number:", value=0.0)

# Select box for selecting operations
operation = st.selectbox(
    "Select an operation",
    ["Add", "Subtract", "Multiply", "Divide", "Power", "Square Root", "log10", "ln", "Sine", "Cosine", "Tangent", "Factorial", "Absolute"]
)

# Perform the selected operation
if operation == "Add":
    result = add(num1, num2)
elif operation == "Subtract":
    result = subtract(num1, num2)
elif operation == "Multiply":
    result = multiply(num1, num2)
elif operation == "Divide":
    result = divide(num1, num2)
elif operation == "Power":
    result = power(num1, num2)
elif operation == "Square Root":
    result = sqrt(num1)
elif operation == "log10":
    result = log10(num1)
elif operation == "ln":
    result = loge(num1)
elif operation == "Sine":
    result = sine(num1)
elif operation == "Cosine":
    result = cosine(num1)
elif operation == "Tangent":
    result = tangent(num1)
elif operation == "Factorial":
    result = factorial(num1)
elif operation == "Absolute":
    result = absolute(num1)

# Display the result
st.write(f"The result of {operation} is: {result}")