File size: 3,572 Bytes
50e1595
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
96
import streamlit as st
import math

# Define a function for the scientific calculator
def scientific_calculator():
    st.title("Scientific Calculator")
    st.write("This is a simple scientific calculator with various functions.")
    
    # Display the operations menu
    operation = st.selectbox(
        "Choose an operation:",
        ["Addition", "Subtraction", "Multiplication", "Division", 
         "Exponentiation", "Square Root", "Sine", "Cosine", "Tangent", "Logarithm"]
    )

    if operation == "Addition":
        num1 = st.number_input("Enter first number:", value=0.0)
        num2 = st.number_input("Enter second number:", value=0.0)
        if st.button("Calculate"):
            result = num1 + num2
            st.write(f"Result: {result}")

    elif operation == "Subtraction":
        num1 = st.number_input("Enter first number:", value=0.0)
        num2 = st.number_input("Enter second number:", value=0.0)
        if st.button("Calculate"):
            result = num1 - num2
            st.write(f"Result: {result}")

    elif operation == "Multiplication":
        num1 = st.number_input("Enter first number:", value=0.0)
        num2 = st.number_input("Enter second number:", value=0.0)
        if st.button("Calculate"):
            result = num1 * num2
            st.write(f"Result: {result}")

    elif operation == "Division":
        num1 = st.number_input("Enter first number:", value=0.0)
        num2 = st.number_input("Enter second number:", value=0.0)
        if st.button("Calculate"):
            if num2 != 0:
                result = num1 / num2
                st.write(f"Result: {result}")
            else:
                st.write("Error: Cannot divide by zero!")

    elif operation == "Exponentiation":
        base = st.number_input("Enter base number:", value=0.0)
        exponent = st.number_input("Enter exponent:", value=0.0)
        if st.button("Calculate"):
            result = math.pow(base, exponent)
            st.write(f"Result: {result}")

    elif operation == "Square Root":
        num = st.number_input("Enter number:", value=0.0)
        if st.button("Calculate"):
            if num >= 0:
                result = math.sqrt(num)
                st.write(f"Result: {result}")
            else:
                st.write("Error: Cannot take square root of negative number!")

    elif operation == "Sine":
        angle = st.number_input("Enter angle in degrees:", value=0.0)
        if st.button("Calculate"):
            angle_rad = math.radians(angle)
            result = math.sin(angle_rad)
            st.write(f"Result: {result}")

    elif operation == "Cosine":
        angle = st.number_input("Enter angle in degrees:", value=0.0)
        if st.button("Calculate"):
            angle_rad = math.radians(angle)
            result = math.cos(angle_rad)
            st.write(f"Result: {result}")

    elif operation == "Tangent":
        angle = st.number_input("Enter angle in degrees:", value=0.0)
        if st.button("Calculate"):
            angle_rad = math.radians(angle)
            result = math.tan(angle_rad)
            st.write(f"Result: {result}")

    elif operation == "Logarithm":
        num = st.number_input("Enter number:", value=0.0)
        if st.button("Calculate"):
            if num > 0:
                result = math.log(num)
                st.write(f"Result: {result}")
            else:
                st.write("Error: Logarithm undefined for non-positive numbers!")

# Call the scientific calculator function
if __name__ == "__main__":
    scientific_calculator()