쉽고 깔끔하게
[프로그래머스/python3] Level 1 핸드폰 번호 가리기 문제풀이 본문
728x90
반응형

문제
programmers.co.kr/learn/courses/30/lessons/12948
코딩테스트 연습 - 핸드폰 번호 가리기
프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다. 전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자
programmers.co.kr
전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *로 가린 문자열을 리턴하는 함수, solutio을 완성해주세요.
<정답>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(phone_number): | |
result = [] | |
for i in range(len(phone_number)): | |
if i < (len(phone_number)-4): | |
result.append('*') | |
else: | |
result.append(phone_number[i]) | |
return ''.join(result) |
728x90
반응형
'Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스/python3] Level 1 2016년 문제풀이 (0) | 2021.02.05 |
---|---|
[프로그래머스/python3] Level 1 시저 암호 문제풀이 (0) | 2021.02.03 |
[프로그래머스/python3] Level 1 예산 문제풀이 (0) | 2021.01.27 |
[프로그래머스/python3] Level 1 자연수 뒤집어 배열로 만들기 문제풀이 (0) | 2021.01.27 |
[프로그래머스/python3] Level 1 직사각형 별찍기 문제풀이 (0) | 2021.01.26 |