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

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
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}")