In python write a hybrid module myListFunc.py for number list operations. This m
ID: 3701942 • Letter: I
Question
In python 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
Your program should meet the following requirements: - No built-in functions (such as max(), min(), count(), replace) are allowed to use in the function definition.
Explanation / Answer
1.)fill up empty list L with user input
def fillList(L):
L=[]
for i in range(5) // Here we are taking 5 numbers
L.append(input('Enter a number'))
print L
2.return maximum value of the list
def maxList(L):
max=-100
for i in L:
if i >max:
max=i
print(max)
3.)def avgList(L):
total=0
for q in L:
total=total+q
average=total/len(L)
return avgList
4.)find number of occurrence of a number,x in a list-:
def count(L, v):
count = 0
for el in L:
if (el== v):
count = count + 1
return count
v = 8
print(count(L, v))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.