Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,15 +113,25 @@ st.latex(r'''
|
|
| 113 |
\text{Median} = \frac{X_{\left(\frac{n}{2}\right)} + X_{\left(\frac{n}{2}+1\right)}}{2}
|
| 114 |
''')
|
| 115 |
def median(list1):
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
else:
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
return list1[
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
list1=[]
|
| 126 |
for i in numbers_input_1:
|
| 127 |
list1+=[int(i)]
|
|
|
|
| 113 |
\text{Median} = \frac{X_{\left(\frac{n}{2}\right)} + X_{\left(\frac{n}{2}+1\right)}}{2}
|
| 114 |
''')
|
| 115 |
def median(list1):
|
| 116 |
+
# Ensure the list is sorted
|
| 117 |
+
list1.sort()
|
| 118 |
+
length = len(list1)
|
| 119 |
+
|
| 120 |
+
if length % 2 == 0:
|
| 121 |
+
# For even length, calculate the average of the two middle values
|
| 122 |
+
mid1 = length // 2 - 1
|
| 123 |
+
mid2 = length // 2
|
| 124 |
+
return (list1[mid1] + list1[mid2]) / 2
|
| 125 |
else:
|
| 126 |
+
# For odd length, return the middle value
|
| 127 |
+
mid = length // 2
|
| 128 |
+
return list1[mid]
|
| 129 |
+
|
| 130 |
+
# Use a unique key for the text input widget to avoid DuplicateWidgetID error
|
| 131 |
+
numbers_input_1 = st.text_input(
|
| 132 |
+
"Enter a list of numbers separated by commas (e.g., 1, 2, 2, 3, 4):",
|
| 133 |
+
key="numbers_input_1"
|
| 134 |
+
)
|
| 135 |
list1=[]
|
| 136 |
for i in numbers_input_1:
|
| 137 |
list1+=[int(i)]
|