10807. 개수 세기

이윤설·2023년 2월 13일
0

내 코드(오답)

N = int(input())
numbers = [1,4,1,2,4,2,4,2,3,4,4]
v = 2
print(numbers.count(2))

정답

n = int(input())
n_list = list(map(int, input().split()))
v = int(input())

print(n_list.count(v))

포인트
1. 길이를 세는 것: len()
갯수를 세는 것: count()

count() 참고: https://www.entity.co.kr/entry/43-%ED%8C%8C%EC%9D%B4%EC%8D%AC-%EB%AC%B8%EC%9E%90%EC%97%B4-count-%EB%A9%94%EC%86%8C%EB%93%9C

  1. list() 함수를 쓰면 input 처럼 요소를 내가 입력할 수 있다.
profile
화려한 외면이 아닌 단단한 내면

0개의 댓글