DOMMETI commited on
Commit
93befb8
·
verified ·
1 Parent(s): 8526a07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
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
- 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
- numbers_input_1= st.text_input("Enter a list of numbers separated by commas (e.g., 1, 2, 2, 3, 4):",key="numbers_input_1")
 
 
 
 
 
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)]