June is Combung

메서드3 본문

python/클래스

메서드3

june__Park 2021. 3. 21. 04:47
class Ex03:

    def test1(self, lst):
        cnt = 0
        for i in range(len(lst)):
            if lst[i]%4 == 0:
                cnt += 1
        return cnt

    def test2(self, lst):
        temp = []
        for i in range(len(lst)):
            if lst[i]%4 == 0:
                temp.append(lst[i])
        return temp


e = Ex03()

lst = [87, 12, 21, 56, 100]

# 문제 1) 4의 배수의 개수를 리턴해주는 메서드
print(e.test1(lst))

# 문제 2) 4의 배수만 리스트 타입으로 리턴해주는 메서드
temp = e.test2(lst)
print(temp)

'python > 클래스' 카테고리의 다른 글

OMR 카드 (클래스 + 메서드)  (0) 2021.03.21
메서드4  (0) 2021.03.21
메서드2  (0) 2021.03.21
메서드  (0) 2021.03.21
기억력 게임  (0) 2021.03.21
Comments