Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Python, please (List sample functions of the following:) Write a function cal

ID: 3721280 • Letter: I

Question

In Python, please (List sample functions of the following:)

Write a function called sumOf(myList), which takes in a list of numbers as a parameter and returns the sum of all of the values in the list. Write a function called productOf(myList), which takes in a list of numbers as a parameter and returns the product of all of the values in the list. Write a function called count(myList,item), which takes in a list and an item and returns an integer representing how many times the item was in the original list. For example, count([1, 2, "the", "test", 3, "is", "the", "best" ], "the") would return 2, but count([1, 2, "the", "test", 3, "is", "the, "best" ]. "Another") would return 0 (note, I am asking you to do the work here, not use native functionality) Write a function called mean (myList) which takes in a list of numbers and returns a decimal value, which is the mean (the statistical "average") of the numbers in the list. Write a function called median(myList) which takes in a list of numbers and returns the value, which is the arithmetic median of that list (the "middle value when the list is sorted into order) Write a function called mode(myList), which takes in a list of numbers and returns the value, which occurs in the list the most times

Explanation / Answer

sum of numbers in the list

def sumOf(myList):
sum = 0
for i in myList:
sum += i
return sum
print " Sum of Numbers in the List = ",(sumOf((5,7,2,0,1,4)))

Output

Product of Numbers

def productOf(myList):
result = 1
for i in myList:
result = result * i
return result
  
input = [5,7,2]
print " Product of Numbers in the List = ",(productOf(input))

Number of occurances of number in the list

def mode(myList,i):
return myList.count(i)

myList = [2,3,2,1,4,2,1]
i = 1
print " Number of occurances of Numbers in the List = ",(mode(myList,i))

OUTPUT

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote