DOMMETI commited on
Commit
2793d86
·
verified ·
1 Parent(s): d969f88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
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
- # 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(
 
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(