Hawk Student Hawk Student - 1 year ago 66
Python Question

How to multiply a certain integer in list?

I am very new to Python... If I were to give a list, my function should return the number of times "5" appears times 50. For example, if I were to call fivePoints([1,3,5,5]) it should return 100 since the number 5 appears twice (2*50). Is creating an empty list necessary? Do I use the count function? This is what I have but I'm probably way off.

def fivePoints(aList):
for i in aList:
return aList

Answer Source

This is one option:

x = [1, 2, 5, 5]
def fivePoints(aList):
    y = [i for i in aList if i == 5]
    z = len(y) * 50
    return z

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download