Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,36 @@ import streamlit as st
|
|
| 2 |
import math
|
| 3 |
import time
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Animation for menu reveal
|
| 9 |
with st.expander("๐๏ธ Open the Menu (Click Me!)"):
|
|
@@ -40,11 +68,10 @@ def show_animation():
|
|
| 40 |
time.sleep(1.5) # Simulate a processing time
|
| 41 |
placeholder.empty()
|
| 42 |
|
| 43 |
-
#
|
| 44 |
if operation in ["โ Addition", "โ Subtraction", "โ๏ธ Multiplication", "โ Division", "๐ข Exponentiation"]:
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
num2 = st.number_input("Enter the second number: ๐ท๏ธ", value=0.0)
|
| 48 |
if st.button("๐ Calculate"):
|
| 49 |
show_animation()
|
| 50 |
if operation == "โ Addition":
|
|
@@ -62,8 +89,7 @@ if operation in ["โ Addition", "โ Subtraction", "โ๏ธ Multiplication", "
|
|
| 62 |
st.success(f"Result: {math.pow(num1, num2)}")
|
| 63 |
|
| 64 |
elif operation == "๐ Square Root":
|
| 65 |
-
|
| 66 |
-
num = st.number_input("Enter the number: ๐ท๏ธ", value=0.0)
|
| 67 |
if st.button("๐ Calculate"):
|
| 68 |
show_animation()
|
| 69 |
if num >= 0:
|
|
@@ -72,8 +98,7 @@ elif operation == "๐ Square Root":
|
|
| 72 |
st.error("๐ซ Error: Cannot calculate the square root of a negative number!")
|
| 73 |
|
| 74 |
elif operation == "๐ Logarithm":
|
| 75 |
-
|
| 76 |
-
num = st.number_input("Enter the number (greater than 0): ๐ท๏ธ", value=1.0)
|
| 77 |
if st.button("๐ Calculate"):
|
| 78 |
show_animation()
|
| 79 |
if num > 0:
|
|
@@ -82,15 +107,13 @@ elif operation == "๐ Logarithm":
|
|
| 82 |
st.error("๐ซ Error: Logarithm undefined for non-positive numbers!")
|
| 83 |
|
| 84 |
elif operation == "๐ก Factorial":
|
| 85 |
-
|
| 86 |
-
num = st.number_input("Enter a non-negative integer: ๐ท๏ธ", value=0, step=1, min_value=0, format="%d")
|
| 87 |
if st.button("๐ Calculate"):
|
| 88 |
show_animation()
|
| 89 |
st.success(f"Result: {math.factorial(num)}")
|
| 90 |
|
| 91 |
elif operation == "๐ Trigonometry (sin, cos, tan)":
|
| 92 |
-
|
| 93 |
-
angle = st.number_input("Enter the angle in degrees: ๐ท๏ธ", value=0.0)
|
| 94 |
if st.button("๐ Calculate"):
|
| 95 |
show_animation()
|
| 96 |
radians = math.radians(angle)
|
|
@@ -99,9 +122,8 @@ elif operation == "๐ Trigonometry (sin, cos, tan)":
|
|
| 99 |
st.write(f"Tan({angle}ยฐ): {math.tan(radians):.4f}")
|
| 100 |
|
| 101 |
elif operation == "๐งฎ Percentage":
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
portion = st.number_input("Enter the portion value: ๐ท๏ธ", value=0.0)
|
| 105 |
if st.button("๐ Calculate Percentage"):
|
| 106 |
show_animation()
|
| 107 |
if total != 0:
|
|
@@ -111,9 +133,8 @@ elif operation == "๐งฎ Percentage":
|
|
| 111 |
st.error("๐ซ Error: Total value cannot be zero!")
|
| 112 |
|
| 113 |
elif operation == "โ Modulus":
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
num2 = st.number_input("Enter the second number: ๐ท๏ธ", value=0.0)
|
| 117 |
if st.button("๐ Calculate Modulus"):
|
| 118 |
show_animation()
|
| 119 |
if num2 != 0:
|
|
@@ -122,8 +143,7 @@ elif operation == "โ Modulus":
|
|
| 122 |
st.error("๐ซ Error: Modulus undefined for division by zero!")
|
| 123 |
|
| 124 |
elif operation == "๐ Inverse (1/x)":
|
| 125 |
-
|
| 126 |
-
num = st.number_input("Enter the number: ๐ท๏ธ", value=0.0)
|
| 127 |
if st.button("๐ Calculate Inverse"):
|
| 128 |
show_animation()
|
| 129 |
if num != 0:
|
|
@@ -132,8 +152,7 @@ elif operation == "๐ Inverse (1/x)":
|
|
| 132 |
st.error("๐ซ Error: Inverse undefined for zero!")
|
| 133 |
|
| 134 |
elif operation == "โก Absolute Value":
|
| 135 |
-
|
| 136 |
-
num = st.number_input("Enter the number: ๐ท๏ธ", value=0.0)
|
| 137 |
if st.button("๐ Calculate Absolute Value"):
|
| 138 |
show_animation()
|
| 139 |
st.success(f"Result: {abs(num)}")
|
|
|
|
| 2 |
import math
|
| 3 |
import time
|
| 4 |
|
| 5 |
+
# Inject custom CSS for the theme
|
| 6 |
+
st.markdown(
|
| 7 |
+
"""
|
| 8 |
+
<style>
|
| 9 |
+
body {
|
| 10 |
+
background: linear-gradient(to right, #6a11cb, #2575fc); /* Blue-purple gradient */
|
| 11 |
+
color: white;
|
| 12 |
+
}
|
| 13 |
+
div[data-testid="stSidebar"] {
|
| 14 |
+
background: #3b3b98; /* Sidebar background */
|
| 15 |
+
}
|
| 16 |
+
div[data-testid="stMarkdownContainer"] h1, div[data-testid="stMarkdownContainer"] h2,
|
| 17 |
+
div[data-testid="stMarkdownContainer"] h3 {
|
| 18 |
+
color: #ffffff; /* Title color */
|
| 19 |
+
}
|
| 20 |
+
button {
|
| 21 |
+
background-color: #2575fc !important; /* Button background */
|
| 22 |
+
color: white !important; /* Button text color */
|
| 23 |
+
border-radius: 5px !important;
|
| 24 |
+
}
|
| 25 |
+
div[data-testid="stMarkdownContainer"] p {
|
| 26 |
+
font-family: 'Trebuchet MS', sans-serif; /* Text style */
|
| 27 |
+
}
|
| 28 |
+
</style>
|
| 29 |
+
""",
|
| 30 |
+
unsafe_allow_html=True,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Title with updated theme
|
| 34 |
+
st.title("๐ Advanced Calculator with Blue-Purple Theme ๐")
|
| 35 |
|
| 36 |
# Animation for menu reveal
|
| 37 |
with st.expander("๐๏ธ Open the Menu (Click Me!)"):
|
|
|
|
| 68 |
time.sleep(1.5) # Simulate a processing time
|
| 69 |
placeholder.empty()
|
| 70 |
|
| 71 |
+
# Logic for operations with input fields
|
| 72 |
if operation in ["โ Addition", "โ Subtraction", "โ๏ธ Multiplication", "โ Division", "๐ข Exponentiation"]:
|
| 73 |
+
num1 = st.number_input("Enter the first number:", value=0.0)
|
| 74 |
+
num2 = st.number_input("Enter the second number:", value=0.0)
|
|
|
|
| 75 |
if st.button("๐ Calculate"):
|
| 76 |
show_animation()
|
| 77 |
if operation == "โ Addition":
|
|
|
|
| 89 |
st.success(f"Result: {math.pow(num1, num2)}")
|
| 90 |
|
| 91 |
elif operation == "๐ Square Root":
|
| 92 |
+
num = st.number_input("Enter the number:", value=0.0)
|
|
|
|
| 93 |
if st.button("๐ Calculate"):
|
| 94 |
show_animation()
|
| 95 |
if num >= 0:
|
|
|
|
| 98 |
st.error("๐ซ Error: Cannot calculate the square root of a negative number!")
|
| 99 |
|
| 100 |
elif operation == "๐ Logarithm":
|
| 101 |
+
num = st.number_input("Enter the number (greater than 0):", value=1.0)
|
|
|
|
| 102 |
if st.button("๐ Calculate"):
|
| 103 |
show_animation()
|
| 104 |
if num > 0:
|
|
|
|
| 107 |
st.error("๐ซ Error: Logarithm undefined for non-positive numbers!")
|
| 108 |
|
| 109 |
elif operation == "๐ก Factorial":
|
| 110 |
+
num = st.number_input("Enter a non-negative integer:", value=0, step=1, min_value=0, format="%d")
|
|
|
|
| 111 |
if st.button("๐ Calculate"):
|
| 112 |
show_animation()
|
| 113 |
st.success(f"Result: {math.factorial(num)}")
|
| 114 |
|
| 115 |
elif operation == "๐ Trigonometry (sin, cos, tan)":
|
| 116 |
+
angle = st.number_input("Enter the angle in degrees:", value=0.0)
|
|
|
|
| 117 |
if st.button("๐ Calculate"):
|
| 118 |
show_animation()
|
| 119 |
radians = math.radians(angle)
|
|
|
|
| 122 |
st.write(f"Tan({angle}ยฐ): {math.tan(radians):.4f}")
|
| 123 |
|
| 124 |
elif operation == "๐งฎ Percentage":
|
| 125 |
+
total = st.number_input("Enter the total value:", value=1.0)
|
| 126 |
+
portion = st.number_input("Enter the portion value:", value=0.0)
|
|
|
|
| 127 |
if st.button("๐ Calculate Percentage"):
|
| 128 |
show_animation()
|
| 129 |
if total != 0:
|
|
|
|
| 133 |
st.error("๐ซ Error: Total value cannot be zero!")
|
| 134 |
|
| 135 |
elif operation == "โ Modulus":
|
| 136 |
+
num1 = st.number_input("Enter the first number:", value=0.0)
|
| 137 |
+
num2 = st.number_input("Enter the second number:", value=0.0)
|
|
|
|
| 138 |
if st.button("๐ Calculate Modulus"):
|
| 139 |
show_animation()
|
| 140 |
if num2 != 0:
|
|
|
|
| 143 |
st.error("๐ซ Error: Modulus undefined for division by zero!")
|
| 144 |
|
| 145 |
elif operation == "๐ Inverse (1/x)":
|
| 146 |
+
num = st.number_input("Enter the number:", value=0.0)
|
|
|
|
| 147 |
if st.button("๐ Calculate Inverse"):
|
| 148 |
show_animation()
|
| 149 |
if num != 0:
|
|
|
|
| 152 |
st.error("๐ซ Error: Inverse undefined for zero!")
|
| 153 |
|
| 154 |
elif operation == "โก Absolute Value":
|
| 155 |
+
num = st.number_input("Enter the number:", value=0.0)
|
|
|
|
| 156 |
if st.button("๐ Calculate Absolute Value"):
|
| 157 |
show_animation()
|
| 158 |
st.success(f"Result: {abs(num)}")
|