코딩테스트 연습 (Python)

1. 문자열 내 p와 y의 개수def solution(s): s = s.lower() return s.count('p') == s.count('y') 우선 lower()를 사용하여 대소문자를 구별하지 않고 개수를 세기 위해 변환합니다.  count()를 활용하여 개수 비교하여 같으면 True, 다르면 False를 반환합니다.  2. 문자열을 정수로 바꾸기 def solution(s): return int(s) 파이썬의 int 함수를 사용하여 문자열 s를 정수로 변환합니다. 3. 약수의 합 def solution(n): solution = 0 for i in range(1, n+1): if n % i == 0: solution += i ..
gonii00
'코딩테스트 연습 (Python)' 카테고리의 글 목록