Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import time
|
| 3 |
|
| 4 |
# Title with Emoji
|
|
@@ -39,7 +40,60 @@ def show_animation():
|
|
| 39 |
time.sleep(1.5) # Simulate a processing time
|
| 40 |
placeholder.empty()
|
| 41 |
|
| 42 |
-
# Add logic for the calculator
|
| 43 |
-
if operation:
|
| 44 |
-
|
| 45 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
import time
|
| 4 |
|
| 5 |
# Title with Emoji
|
|
|
|
| 40 |
time.sleep(1.5) # Simulate a processing time
|
| 41 |
placeholder.empty()
|
| 42 |
|
| 43 |
+
# Add logic for the calculator with input fields
|
| 44 |
+
if operation in ["β Addition", "β Subtraction", "βοΈ Multiplication", "β Division", "π’ Exponentiation"]:
|
| 45 |
+
# Input fields for two numbers
|
| 46 |
+
num1 = st.number_input("Enter the first number: π·οΈ", value=0.0)
|
| 47 |
+
num2 = st.number_input("Enter the second number: π·οΈ", value=0.0)
|
| 48 |
+
if st.button("π Calculate"):
|
| 49 |
+
show_animation()
|
| 50 |
+
if operation == "β Addition":
|
| 51 |
+
st.success(f"Result: {num1 + num2}")
|
| 52 |
+
elif operation == "β Subtraction":
|
| 53 |
+
st.success(f"Result: {num1 - num2}")
|
| 54 |
+
elif operation == "βοΈ Multiplication":
|
| 55 |
+
st.success(f"Result: {num1 * num2}")
|
| 56 |
+
elif operation == "β Division":
|
| 57 |
+
if num2 != 0:
|
| 58 |
+
st.success(f"Result: {num1 / num2}")
|
| 59 |
+
else:
|
| 60 |
+
st.error("π« Error: Division by zero is not allowed!")
|
| 61 |
+
elif operation == "π’ Exponentiation":
|
| 62 |
+
st.success(f"Result: {math.pow(num1, num2)}")
|
| 63 |
+
|
| 64 |
+
elif operation == "π Square Root":
|
| 65 |
+
# Input field for one number
|
| 66 |
+
num = st.number_input("Enter the number: π·οΈ", value=0.0)
|
| 67 |
+
if st.button("π Calculate"):
|
| 68 |
+
show_animation()
|
| 69 |
+
if num >= 0:
|
| 70 |
+
st.success(f"Result: {math.sqrt(num)}")
|
| 71 |
+
else:
|
| 72 |
+
st.error("π« Error: Cannot calculate the square root of a negative number!")
|
| 73 |
+
|
| 74 |
+
elif operation == "π Logarithm":
|
| 75 |
+
# Input field for one positive number
|
| 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:
|
| 80 |
+
st.success(f"Result: {math.log(num)}")
|
| 81 |
+
else:
|
| 82 |
+
st.error("π« Error: Logarithm undefined for non-positive numbers!")
|
| 83 |
+
|
| 84 |
+
elif operation == "π‘ Factorial":
|
| 85 |
+
# Input field for non-negative integers only
|
| 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 |
+
# Input field for angle in degrees
|
| 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)
|
| 97 |
+
st.write(f"Sin({angle}Β°): {math.sin(radians):.4f}")
|
| 98 |
+
st.write(f"Cos({angle}Β°): {math.cos(radians):.4f}")
|
| 99 |
+
st.write(f"Tan({angle}Β°): {math.tan(radians):.4f}")
|