nightprogrammer commited on
Commit
c06e644
Β·
verified Β·
1 Parent(s): 8873371

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -75
app.py CHANGED
@@ -1,80 +1,45 @@
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}")
 
1
  import streamlit as st
 
2
  import time
3
 
4
  # Title with Emoji
5
+ st.title("πŸ’« Advanced Calculator with Menu Animation πŸ’»")
6
+
7
+ # Animation for menu reveal
8
+ with st.expander("πŸŽ›οΈ Open the Menu (Click Me!)"):
9
+ st.markdown(
10
+ """
11
+ <style>
12
+ @keyframes fadeIn {
13
+ from {opacity: 0;}
14
+ to {opacity: 1;}
15
+ }
16
+ div[data-testid="stMarkdownContainer"] {
17
+ animation: fadeIn 1s ease-in-out;
18
+ }
19
+ </style>
20
+ """,
21
+ unsafe_allow_html=True,
22
+ )
23
+
24
+ # Menu options with animated reveal
25
+ operation = st.selectbox(
26
+ "Choose an operation:",
27
+ [
28
+ "βž• Addition", "βž– Subtraction", "βœ–οΈ Multiplication", "βž— Division",
29
+ "πŸ”’ Exponentiation", "🌟 Square Root", "πŸ“ Logarithm", "πŸ’‘ Factorial",
30
+ "🌐 Trigonometry (sin, cos, tan)"
31
+ ]
32
+ )
33
+
34
+ # Animation function for smooth transitions
35
  def show_animation():
36
+ placeholder = st.empty()
37
+ with placeholder:
38
+ st.info("✨ Loading your selection...")
39
+ time.sleep(1.5) # Simulate a processing time
40
+ placeholder.empty()
41
+
42
+ # Add logic for the calculator
43
+ if operation:
44
+ show_animation()
45
+ st.success(f"πŸŽ‰ You selected: {operation} πŸŽ‰")