머쓱이는 친구들과 369게임을 하고 있습니다. 369게임은 1부터 숫자를 하나씩 대며 3, 6, 9가 들어가는 숫자는 숫자 대신 3, 6, 9의 개수만큼 박수를 치는 게임입니다. 머쓱이가 말해야하는 숫자 order가 매개변수로 주어질 때, 머쓱이가 쳐야할 박수 횟수를 return 하도록 solution 함수를 완성해보세요.
code - 1차
def solution(order):
count = 0
for n in str(order):
if n == "3" or n == "6" or n == "9":
count += 1
return count
code - 2차
def solution(order):
order_count = str(order).count('3') + str(order).count('6') + str(order).count('9')
return order_count
https://github.com/seonmin5/codingtest_Python
GitHub - seonmin5/codingtest_Python
Contribute to seonmin5/codingtest_Python development by creating an account on GitHub.
github.com
반응형
'Python' 카테고리의 다른 글
[Python/level 0] 문자열 잘라서 정렬하기 - 181866, filter(function, iterable) (1) | 2024.08.31 |
---|---|
[Python/level 0] 문자열 정렬하기 (2) - 120911, sorted (0) | 2024.08.31 |
[Python/level 1] 모의고사 - 42840, enumerate(iterable, start=0) (1) | 2024.08.30 |
[Python/level 0] 인덱스 바꾸기 - 120895, 리스트 (0) | 2024.08.30 |
[Python/level 0] 문자열의 뒤의 n글자 - 181910, len, 리스트 슬라이싱 (0) | 2024.08.30 |