nightprogrammer commited on
Commit
987710a
ยท
verified ยท
1 Parent(s): 54b46fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -24
app.py CHANGED
@@ -2,8 +2,36 @@ import streamlit as st
2
  import math
3
  import time
4
 
5
- # Title with Emoji
6
- st.title("๐Ÿ’ซ Advanced Calculator with More Operations ๐Ÿ’ป")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Animation for menu reveal
9
  with st.expander("๐ŸŽ›๏ธ Open the Menu (Click Me!)"):
@@ -40,11 +68,10 @@ def show_animation():
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":
@@ -62,8 +89,7 @@ if operation in ["โž• Addition", "โž– Subtraction", "โœ–๏ธ Multiplication", "
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:
@@ -72,8 +98,7 @@ elif operation == "๐ŸŒŸ Square Root":
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:
@@ -82,15 +107,13 @@ elif operation == "๐Ÿ“ Logarithm":
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)
@@ -99,9 +122,8 @@ elif operation == "๐ŸŒ Trigonometry (sin, cos, tan)":
99
  st.write(f"Tan({angle}ยฐ): {math.tan(radians):.4f}")
100
 
101
  elif operation == "๐Ÿงฎ Percentage":
102
- # Calculate percentage
103
- total = st.number_input("Enter the total value: ๐Ÿท๏ธ", value=1.0)
104
- portion = st.number_input("Enter the portion value: ๐Ÿท๏ธ", value=0.0)
105
  if st.button("๐Ÿ“Š Calculate Percentage"):
106
  show_animation()
107
  if total != 0:
@@ -111,9 +133,8 @@ elif operation == "๐Ÿงฎ Percentage":
111
  st.error("๐Ÿšซ Error: Total value cannot be zero!")
112
 
113
  elif operation == "โž— Modulus":
114
- # Calculate modulus
115
- num1 = st.number_input("Enter the first number: ๐Ÿท๏ธ", value=0.0)
116
- num2 = st.number_input("Enter the second number: ๐Ÿท๏ธ", value=0.0)
117
  if st.button("๐Ÿ“Š Calculate Modulus"):
118
  show_animation()
119
  if num2 != 0:
@@ -122,8 +143,7 @@ elif operation == "โž— Modulus":
122
  st.error("๐Ÿšซ Error: Modulus undefined for division by zero!")
123
 
124
  elif operation == "๐Ÿ”„ Inverse (1/x)":
125
- # Calculate inverse
126
- num = st.number_input("Enter the number: ๐Ÿท๏ธ", value=0.0)
127
  if st.button("๐Ÿ“Š Calculate Inverse"):
128
  show_animation()
129
  if num != 0:
@@ -132,8 +152,7 @@ elif operation == "๐Ÿ”„ Inverse (1/x)":
132
  st.error("๐Ÿšซ Error: Inverse undefined for zero!")
133
 
134
  elif operation == "โšก Absolute Value":
135
- # Calculate absolute value
136
- num = st.number_input("Enter the number: ๐Ÿท๏ธ", value=0.0)
137
  if st.button("๐Ÿ“Š Calculate Absolute Value"):
138
  show_animation()
139
  st.success(f"Result: {abs(num)}")
 
2
  import math
3
  import time
4
 
5
+ # Inject custom CSS for the theme
6
+ st.markdown(
7
+ """
8
+ <style>
9
+ body {
10
+ background: linear-gradient(to right, #6a11cb, #2575fc); /* Blue-purple gradient */
11
+ color: white;
12
+ }
13
+ div[data-testid="stSidebar"] {
14
+ background: #3b3b98; /* Sidebar background */
15
+ }
16
+ div[data-testid="stMarkdownContainer"] h1, div[data-testid="stMarkdownContainer"] h2,
17
+ div[data-testid="stMarkdownContainer"] h3 {
18
+ color: #ffffff; /* Title color */
19
+ }
20
+ button {
21
+ background-color: #2575fc !important; /* Button background */
22
+ color: white !important; /* Button text color */
23
+ border-radius: 5px !important;
24
+ }
25
+ div[data-testid="stMarkdownContainer"] p {
26
+ font-family: 'Trebuchet MS', sans-serif; /* Text style */
27
+ }
28
+ </style>
29
+ """,
30
+ unsafe_allow_html=True,
31
+ )
32
+
33
+ # Title with updated theme
34
+ st.title("๐Ÿš€ Advanced Calculator with Blue-Purple Theme ๐ŸŒˆ")
35
 
36
  # Animation for menu reveal
37
  with st.expander("๐ŸŽ›๏ธ Open the Menu (Click Me!)"):
 
68
  time.sleep(1.5) # Simulate a processing time
69
  placeholder.empty()
70
 
71
+ # Logic for operations with input fields
72
  if operation in ["โž• Addition", "โž– Subtraction", "โœ–๏ธ Multiplication", "โž— Division", "๐Ÿ”ข Exponentiation"]:
73
+ num1 = st.number_input("Enter the first number:", value=0.0)
74
+ num2 = st.number_input("Enter the second number:", value=0.0)
 
75
  if st.button("๐Ÿ“Š Calculate"):
76
  show_animation()
77
  if operation == "โž• Addition":
 
89
  st.success(f"Result: {math.pow(num1, num2)}")
90
 
91
  elif operation == "๐ŸŒŸ Square Root":
92
+ num = st.number_input("Enter the number:", value=0.0)
 
93
  if st.button("๐Ÿ“Š Calculate"):
94
  show_animation()
95
  if num >= 0:
 
98
  st.error("๐Ÿšซ Error: Cannot calculate the square root of a negative number!")
99
 
100
  elif operation == "๐Ÿ“ Logarithm":
101
+ num = st.number_input("Enter the number (greater than 0):", value=1.0)
 
102
  if st.button("๐Ÿ“Š Calculate"):
103
  show_animation()
104
  if num > 0:
 
107
  st.error("๐Ÿšซ Error: Logarithm undefined for non-positive numbers!")
108
 
109
  elif operation == "๐Ÿ’ก Factorial":
110
+ num = st.number_input("Enter a non-negative integer:", value=0, step=1, min_value=0, format="%d")
 
111
  if st.button("๐Ÿ“Š Calculate"):
112
  show_animation()
113
  st.success(f"Result: {math.factorial(num)}")
114
 
115
  elif operation == "๐ŸŒ Trigonometry (sin, cos, tan)":
116
+ angle = st.number_input("Enter the angle in degrees:", value=0.0)
 
117
  if st.button("๐Ÿ“Š Calculate"):
118
  show_animation()
119
  radians = math.radians(angle)
 
122
  st.write(f"Tan({angle}ยฐ): {math.tan(radians):.4f}")
123
 
124
  elif operation == "๐Ÿงฎ Percentage":
125
+ total = st.number_input("Enter the total value:", value=1.0)
126
+ portion = st.number_input("Enter the portion value:", value=0.0)
 
127
  if st.button("๐Ÿ“Š Calculate Percentage"):
128
  show_animation()
129
  if total != 0:
 
133
  st.error("๐Ÿšซ Error: Total value cannot be zero!")
134
 
135
  elif operation == "โž— Modulus":
136
+ num1 = st.number_input("Enter the first number:", value=0.0)
137
+ num2 = st.number_input("Enter the second number:", value=0.0)
 
138
  if st.button("๐Ÿ“Š Calculate Modulus"):
139
  show_animation()
140
  if num2 != 0:
 
143
  st.error("๐Ÿšซ Error: Modulus undefined for division by zero!")
144
 
145
  elif operation == "๐Ÿ”„ Inverse (1/x)":
146
+ num = st.number_input("Enter the number:", value=0.0)
 
147
  if st.button("๐Ÿ“Š Calculate Inverse"):
148
  show_animation()
149
  if num != 0:
 
152
  st.error("๐Ÿšซ Error: Inverse undefined for zero!")
153
 
154
  elif operation == "โšก Absolute Value":
155
+ num = st.number_input("Enter the number:", value=0.0)
 
156
  if st.button("๐Ÿ“Š Calculate Absolute Value"):
157
  show_animation()
158
  st.success(f"Result: {abs(num)}")