Trying to solve leetcode questions with python3. This question is just asking for some simple stat calculations, but I can't even get the code to run because I don't understand what the problem is. The names are spelled the same, the function is defined before it is called, is it something with the parameter?
class Solution:
def minFinder(nums):
min = nums[0]
for num in nums:
if (num < min):
min = num
return min
def maxFinder(nums):
max = nums[0]
for num in nums:
if (num > min):
max = num
return max
def meanFinder(nums):
sum = 0
for num in nums:
sum += num
mean = sum/(len(nums))
return mean
def medFinder(nums):
if (len(nums) % 2 == 0):
med = nums[((len(nums)/2 - 1) + (len(nums)/2)) / 2]
else:
med = nums[len(nums) // 2]
return med
def modeFinder(nums):
index = 0
freq = 0
for num in nums:
if nums.count(num) > freq:
freq = nums.count(num)
index = nums.index(num)
mode = nums[index]
return mode
def sampleStats(self, count: List[int]) -> List[float]:
fltr_cnt = []
for num in count:
if (num != 0):
fltr_cnt.append(num)
stats = []
stats.append(minFinder(fltr_cnt) * 1.0)
stats.append(maxFinder(fltr_cnt))
stats.append(meanFinder(fltr_cnt))
stats.append(medFinder(fltr_cnt))
stats.append(modeFinder(fltr_cnt))
return stats
name 'minFinder' is not defined
Advice to make my code less complex also appreciated, like is there a faster way to do .append() 5 times?