Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
# Title with Emoji
|
| 6 |
+
st.title("π Advanced Calculator with Animations π")
|
| 7 |
+
|
| 8 |
+
# Sidebar for navigation
|
| 9 |
+
st.sidebar.title("π§ Calculator Options")
|
| 10 |
+
operation = st.sidebar.selectbox(
|
| 11 |
+
"Choose an operation:",
|
| 12 |
+
[
|
| 13 |
+
"β Addition", "β Subtraction", "βοΈ Multiplication", "β Division",
|
| 14 |
+
"π’ Exponentiation", "π Square Root", "π Logarithm", "π‘ Factorial",
|
| 15 |
+
"π Trigonometry (sin, cos, tan)"
|
| 16 |
+
]
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Animation function
|
| 20 |
+
def show_animation():
|
| 21 |
+
with st.spinner("Calculating..."):
|
| 22 |
+
time.sleep(1) # Simulate processing
|
| 23 |
+
st.success("β
Done!")
|
| 24 |
+
|
| 25 |
+
# Input for basic operations
|
| 26 |
+
if operation in ["β Addition", "β Subtraction", "βοΈ Multiplication", "β Division", "π’ Exponentiation"]:
|
| 27 |
+
num1 = st.number_input("Enter the first number: π·οΈ", value=0.0)
|
| 28 |
+
num2 = st.number_input("Enter the second number: π·οΈ", value=0.0)
|
| 29 |
+
if st.button("π Calculate"):
|
| 30 |
+
show_animation()
|
| 31 |
+
if operation == "β Addition":
|
| 32 |
+
st.success(f"Result: {num1 + num2}")
|
| 33 |
+
elif operation == "β Subtraction":
|
| 34 |
+
st.success(f"Result: {num1 - num2}")
|
| 35 |
+
elif operation == "βοΈ Multiplication":
|
| 36 |
+
st.success(f"Result: {num1 * num2}")
|
| 37 |
+
elif operation == "β Division":
|
| 38 |
+
if num2 != 0:
|
| 39 |
+
st.success(f"Result: {num1 / num2}")
|
| 40 |
+
else:
|
| 41 |
+
st.error("π« Error: Division by zero is not allowed!")
|
| 42 |
+
elif operation == "π’ Exponentiation":
|
| 43 |
+
st.success(f"Result: {math.pow(num1, num2)}")
|
| 44 |
+
|
| 45 |
+
# Square Root Calculation
|
| 46 |
+
elif operation == "π Square Root":
|
| 47 |
+
num = st.number_input("Enter the number: π·οΈ", value=0.0)
|
| 48 |
+
if st.button("π Calculate"):
|
| 49 |
+
show_animation()
|
| 50 |
+
if num >= 0:
|
| 51 |
+
st.success(f"Result: {math.sqrt(num)}")
|
| 52 |
+
else:
|
| 53 |
+
st.error("π« Error: Cannot calculate the square root of a negative number!")
|
| 54 |
+
|
| 55 |
+
# Logarithm Calculation
|
| 56 |
+
elif operation == "π Logarithm":
|
| 57 |
+
num = st.number_input("Enter the number (greater than 0): π·οΈ", value=1.0)
|
| 58 |
+
if st.button("π Calculate"):
|
| 59 |
+
show_animation()
|
| 60 |
+
if num > 0:
|
| 61 |
+
st.success(f"Result: {math.log(num)}")
|
| 62 |
+
else:
|
| 63 |
+
st.error("π« Error: Logarithm undefined for non-positive numbers!")
|
| 64 |
+
|
| 65 |
+
# Factorial Calculation
|
| 66 |
+
elif operation == "π‘ Factorial":
|
| 67 |
+
num = st.number_input("Enter a non-negative integer: π·οΈ", value=0, step=1, min_value=0, format="%d")
|
| 68 |
+
if st.button("π Calculate"):
|
| 69 |
+
show_animation()
|
| 70 |
+
st.success(f"Result: {math.factorial(num)}")
|
| 71 |
+
|
| 72 |
+
# Trigonometry
|
| 73 |
+
elif operation == "π Trigonometry (sin, cos, tan)":
|
| 74 |
+
angle = st.number_input("Enter the angle in degrees: π·οΈ", value=0.0)
|
| 75 |
+
if st.button("π Calculate"):
|
| 76 |
+
show_animation()
|
| 77 |
+
radians = math.radians(angle)
|
| 78 |
+
st.write(f"Sin({angle}Β°): {math.sin(radians):.4f}")
|
| 79 |
+
st.write(f"Cos({angle}Β°): {math.cos(radians):.4f}")
|
| 80 |
+
st.write(f"Tan({angle}Β°): {math.tan(radians):.4f}")
|