Hawk Student
Hawk Student

Reputation: 147

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:
            i.count(5*50)
        return aList

Upvotes: 1

Views: 71

Answers (2)

Olivier Pellier-Cuit
Olivier Pellier-Cuit

Reputation: 1279

You want to return a number. You just have to write:

def fivePoints(aList):
    return aList.count(5)*50

print(fivePoints([1,3,5,5]))

Upvotes: 4

estebanpdl
estebanpdl

Reputation: 1233

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

fivePoints(x)
100

Upvotes: 2

Related Questions