Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import math
|
3 |
+
|
4 |
+
# Title of the app
|
5 |
+
st.title("🧮 Scientific Calculator")
|
6 |
+
|
7 |
+
# Description
|
8 |
+
st.write("Perform various mathematical operations including basic arithmetic, logarithms, trigonometric functions, and more.")
|
9 |
+
|
10 |
+
# Dropdown menu for operations
|
11 |
+
operation = st.selectbox(
|
12 |
+
"Select an operation:",
|
13 |
+
[
|
14 |
+
"Addition",
|
15 |
+
"Subtraction",
|
16 |
+
"Multiplication",
|
17 |
+
"Division",
|
18 |
+
"Power",
|
19 |
+
"Square Root",
|
20 |
+
"Logarithm (base 10)",
|
21 |
+
"Natural Logarithm (ln)",
|
22 |
+
"Sine",
|
23 |
+
"Cosine",
|
24 |
+
"Tangent"
|
25 |
+
]
|
26 |
+
)
|
27 |
+
|
28 |
+
# Input fields for operations
|
29 |
+
if operation in ["Addition", "Subtraction", "Multiplication", "Division", "Power"]:
|
30 |
+
num1 = st.number_input("Enter the first number:", format="%.2f")
|
31 |
+
num2 = st.number_input("Enter the second number:", format="%.2f")
|
32 |
+
if st.button("Calculate"):
|
33 |
+
if operation == "Addition":
|
34 |
+
st.success(f"Result: {num1} + {num2} = {num1 + num2}")
|
35 |
+
elif operation == "Subtraction":
|
36 |
+
st.success(f"Result: {num1} - {num2} = {num1 - num2}")
|
37 |
+
elif operation == "Multiplication":
|
38 |
+
st.success(f"Result: {num1} * {num2} = {num1 * num2}")
|
39 |
+
elif operation == "Division":
|
40 |
+
if num2 != 0:
|
41 |
+
st.success(f"Result: {num1} / {num2} = {num1 / num2}")
|
42 |
+
else:
|
43 |
+
st.error("Error: Division by zero is not allowed.")
|
44 |
+
elif operation == "Power":
|
45 |
+
st.success(f"Result: {num1} ^ {num2} = {math.pow(num1, num2)}")
|
46 |
+
|
47 |
+
elif operation == "Square Root":
|
48 |
+
num = st.number_input("Enter the number:", format="%.2f")
|
49 |
+
if st.button("Calculate"):
|
50 |
+
if num >= 0:
|
51 |
+
st.success(f"Result: √{num} = {math.sqrt(num)}")
|
52 |
+
else:
|
53 |
+
st.error("Error: Square root of a negative number is not allowed.")
|
54 |
+
|
55 |
+
elif operation == "Logarithm (base 10)":
|
56 |
+
num = st.number_input("Enter the number:", format="%.2f")
|
57 |
+
if st.button("Calculate"):
|
58 |
+
if num > 0:
|
59 |
+
st.success(f"Result: log10({num}) = {math.log10(num)}")
|
60 |
+
else:
|
61 |
+
st.error("Error: Logarithm is only defined for positive numbers.")
|
62 |
+
|
63 |
+
elif operation == "Natural Logarithm (ln)":
|
64 |
+
num = st.number_input("Enter the number:", format="%.2f")
|
65 |
+
if st.button("Calculate"):
|
66 |
+
if num > 0:
|
67 |
+
st.success(f"Result: ln({num}) = {math.log(num)}")
|
68 |
+
else:
|
69 |
+
st.error("Error: Natural logarithm is only defined for positive numbers.")
|
70 |
+
|
71 |
+
elif operation in ["Sine", "Cosine", "Tangent"]:
|
72 |
+
angle = st.number_input("Enter the angle in degrees:", format="%.2f")
|
73 |
+
if st.button("Calculate"):
|
74 |
+
radians = math.radians(angle)
|
75 |
+
if operation == "Sine":
|
76 |
+
st.success(f"Result: sin({angle}) = {math.sin(radians)}")
|
77 |
+
elif operation == "Cosine":
|
78 |
+
st.success(f"Result: cos({angle}) = {math.cos(radians)}")
|
79 |
+
elif operation == "Tangent":
|
80 |
+
st.success(f"Result: tan({angle}) = {math.tan(radians)}")
|