Notice
Recent Posts
Link
- Today
- Total
hye-log
[프로그래머스]없는 숫자 더하기(Python) 본문
0. 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/86051
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 문제 설명
1) 0부터 9까지의 합 구하기
2) 주어진 리스트의 합 구하기
3) 두 합의 차 구하기
2. 입출력
# input
numbers = [1,2,3,4,6,7,8,0]
# output
answer = 14
3. 코드
1) 첫 번째 코드
def solution(numbers):
# numbers : 숫자를 찾을 리스트
answer = -1
# 0부터 10까지의 합
sum_toten = 0
for i in range(0, 10):
sum_toten += i
# numbers의 합
sum_numbers = sum(numbers)
# 두 합의 차 return
answer = sum_toten-sum_numbers
return answer
실행 결과
4. 알게된 점
1) 리스트의 합
list = [1, 2, 3, 4, 5]
print(sum(list)) # 15
5. Github
https://github.com/iihye/Algorithm/blob/main/Programmers/missing_number.py
GitHub - iihye/Algorithm
Contribute to iihye/Algorithm development by creating an account on GitHub.
github.com
728x90
'CodingTest > Programmers' 카테고리의 다른 글
[프로그래머스]내적(Python) (0) | 2022.07.21 |
---|---|
[프로그래머스]음양 더하기(Python) (0) | 2022.07.20 |
[프로그래머스]키패드 누르기(Python) (0) | 2022.07.18 |
[프로그래머스]숫자 문자열과 영단어(Python) (0) | 2022.07.12 |
[프로그래머스]신규 아이디 추천(Python) (0) | 2022.07.12 |
Comments