[프로그래머스]없는 숫자 더하기(Python)

2022. 7. 19. 18:28·CodingTest/Programmers

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
'CodingTest/Programmers' 카테고리의 다른 글
  • [프로그래머스]내적(Python)
  • [프로그래머스]음양 더하기(Python)
  • [프로그래머스]키패드 누르기(Python)
  • [프로그래머스]숫자 문자열과 영단어(Python)
iihye_
iihye_
  • iihye_
    hye-log
    iihye_
    • 분류 전체보기 (296)
      • Development (19)
        • Spring (4)
        • Python (5)
        • React (4)
        • Next.js (1)
        • JavaScript (4)
        • CSS (1)
      • Infra (15)
        • Docker (1)
        • Jenkins (2)
        • Nginx (3)
        • JBoss (1)
        • Windows (3)
        • Linux (3)
        • Kafka (2)
      • Database (1)
        • MongoDB (1)
      • Tools (2)
        • Git (0)
        • Github (1)
        • Document (1)
      • CodingTest (125)
        • Programmers (38)
        • Baekjoon (52)
        • SWEA (27)
        • Jungol (4)
        • Codetree (1)
        • Goorm (3)
      • Education (99)
        • SSAFY 10기 (5)
        • AI Tech 4기 (94)
      • NomadCoder (35)
        • (JS)크롬 앱 만들기 (35)
      • Notice (0)
  • 링크

    • Github
  • 인기 글

  • 최근 글

  • 전체
    오늘
    어제
  • hELLO· Designed By정상우.v4.10.5
iihye_
[프로그래머스]없는 숫자 더하기(Python)
상단으로

티스토리툴바