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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -4
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
- show_animation()
45
- st.success(f"πŸŽ‰ You selected: {operation} πŸŽ‰")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}")