Beginner Python Tutorial - Mean Median and Mode

preview_player
Показать описание
In this short lesson, we create a simple Python program that calculates the mean, median, and mode from a set of numbers.

#python3 #pythontutorial #learntocode

Intro music by GhostxMachine

Рекомендации по теме
Комментарии
Автор

For mean, another clean way to do this, without using a for loop would be:

def mean(nums):
return sum(nums) / len(sums)

print(mean([2, 5, 9, 8, 6, 2, 5, 4]))

# this will print the mean of this list of numbers. We defined a function called mean, and have a parameter of "nums" that will pass through it. We then used the return function to take the sum(nums) and divide them by the length(nums). Finally, we called the mean function with a random list of numbers! Should equal 5.25, or if you wanted only integers and no float (decimal numbers), you could add a second divide symbol .... return sum(nums) // len(sums) = 5

UnpopularGameGuy
Автор

Thanks this tutorial was so good and easy to understand! :)

almightysun
Автор

Here is the code for multiple modes in the list.

def find_mode(list_n):
#let convert list into sets so no duplicates
new_set = set(list_n)
new_list = list(new_set)
counts = []
for i in range(len(new_list)):
counts += [list_n.count(new_list[i])]
max_count = max(counts)

index = counts.index(max_count)
print(new_list[index], end=" ")

for i in range(index+1, len(counts)):
if(max_count == counts[i]):
print(new_list[i], end=" ")


# Taking the input as integers using the map function
list_n = list(map(int, input().split()))

#calling function
find_mode(list_n)

venkannababu
Автор

Thank you so much for this tutorial! You are a great help! Definitely subscribing!

louierattatouie
Автор

Nice video, however, the code you wrote for fining mode will only work finding one mode.and in most cases there are multiple modes in lists.also if your list has same amount of different numbers(for example [2, 2, 3, 3]) then it will still say that mode is 2 in this case when there is no mode.

vazhaabdu
Автор

IDK why you didn't show how to find median if we have 5 numbers / if there was one number in middle

renee
Автор

can you show this while not using a cut and paste from another site? where would the numbers we want a mean, median and mode from be actually typed into the code and how?

paulmcgreevy
Автор

what we do, when we have execute more no of modes in a given list. how can we run

srimanikanta
Автор

This mode coding is only for an unimodal distribution. How about a multimodal i.e bimodal?

borykalderassoumou
Автор

How come the tuple values change once after declared?
In a list of no recurring numbers how does the func returns the least value in the list? I mean where does the sort happen?
Please Explain!
thank you.

johnkiruba
Автор

How to print two modes in single line ( if Two modes in list)

guttamuneendra
Автор

the program only shows one mode even if there are two, anyways thanks a lot

ladislousfarawadya
Автор

what's that ' != 0 ' in the median part? I tried it out and it said invalid syntax, i need help, thanks.

bilalwarsi
Автор

Hey how can we add input field dynamically ?

bikramchettri
Автор

You said simple? explodes in shear stupidity.

majorgeneral
Автор

When I try the mode, the answer is always the first number in the list.
Ex. (3, 4, 5, 5, 6) the mode should be 5 but it outputs 3.
Could you see if it does the same thing for yours?

yohomietony
Автор

what if i want to enter the size of the list and then enter my list and calculate it ?

noufalsuhaim