File size: 2,223 Bytes
d099335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import math
import streamlit as st

# Define functions for basic 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 x / y
    else:
        return "Error! Division by zero."

def square_root(x):
    if x >= 0:
        return math.sqrt(x)
    else:
        return "Error! Negative input."

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

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))

# Streamlit App
st.title("Calculator App")
st.sidebar.title("Operations Menu")

# Menu for selecting operations
operation = st.sidebar.selectbox(
    "Select operation:",
    ["Add", "Subtract", "Multiply", "Divide", "Square Root", "Power", "Sine", "Cosine", "Tangent"]
)

# Inputs based on selected operation
if operation in ["Add", "Subtract", "Multiply", "Divide", "Power"]:
    x = st.number_input("Enter the first number:", value=0.0)
    y = st.number_input("Enter the second number:", value=0.0)
    if st.button("Calculate"):
        if operation == "Add":
            st.write(f"Result: {x} + {y} = {add(x, y)}")
        elif operation == "Subtract":
            st.write(f"Result: {x} - {y} = {subtract(x, y)}")
        elif operation == "Multiply":
            st.write(f"Result: {x} * {y} = {multiply(x, y)}")
        elif operation == "Divide":
            st.write(f"Result: {x} / {y} = {divide(x, y)}")
        elif operation == "Power":
            st.write(f"Result: {x} ^ {y} = {power(x, y)}")

elif operation == "Square Root":
    x = st.number_input("Enter the number:", value=0.0)
    if st.button("Calculate"):
        st.write(f"Result: √{x} = {square_root(x)}")

elif operation in ["Sine", "Cosine", "Tangent"]:
    x = st.number_input("Enter the angle (in degrees):", value=0.0)
    if st.button("Calculate"):
        if operation == "Sine":
            st.write(f"Result: sin({x}°) = {sine(x)}")
        elif operation == "Cosine":
            st.write(f"Result: cos({x}°) = {cosine(x)}")
        elif operation == "Tangent":
            st.write(f"Result: tan({x}°) = {tangent(x)}")