In python language write a hybrid module myListFunc.py for number list operation
ID: 3701919 • Letter: I
Question
In python language write a hybrid module myListFunc.py for number list operations. This module should include the following functions:
- fillList(L): fill up the empty list L with user input
- maxList(L): return the maximum value of the list L
- avgList(L): return the average value of the list L
- count(v, L): count the number of occurrences of number v in the list L
- replace(old, new, L): replace the old number value with new number value in the list L
Explanation / Answer
def fillList(L): n = input('How many numbers: ') for i in range(n): L.append(int(input())) def maxList(L): max_val = L[0] for num in L: if num > max_val: max_val = num return max_val def avgList(L): total = 0 for num in L: total += num return total / len(L) def count(v, L): c = 0 for num in L: if num == v: c += 1 return c def replace(old, new, L): for i in range(len(L)): if L[i] == old: L[i] = new
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.