Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,19 +113,14 @@ 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 |
-
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 |
-
|
| 127 |
-
|
| 128 |
-
return list1[
|
| 129 |
|
| 130 |
# Use a unique key for the text input widget to avoid DuplicateWidgetID error
|
| 131 |
numbers_input_1 = st.text_input(
|
|
|
|
| 113 |
\text{Median} = \frac{X_{\left(\frac{n}{2}\right)} + X_{\left(\frac{n}{2}+1\right)}}{2}
|
| 114 |
''')
|
| 115 |
def median(list1):
|
| 116 |
+
length=len(list1)
|
| 117 |
+
if length%2== 0:
|
| 118 |
+
even_median_value=((length/2)+(length/2)+1)/2
|
| 119 |
+
return (list1[int(even_median_value)]+ list1[int(even_median_value)-1])/2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
else:
|
| 121 |
+
odd_median=((length/2)+1)
|
| 122 |
+
odd_median_value=math.floor(odd_median)
|
| 123 |
+
return list1[odd_median_value-1]
|
| 124 |
|
| 125 |
# Use a unique key for the text input widget to avoid DuplicateWidgetID error
|
| 126 |
numbers_input_1 = st.text_input(
|