[SW Expert Academy, SWEA 2058] 자릿수 더하기 (python)
Problem Solving/SWEA

[SW Expert Academy, SWEA 2058] 자릿수 더하기 (python)

728x90

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=1&contestProbId=AV5QPRjqA10DFAUq&categoryId=AV5QPRjqA10DFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=1&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com


※ SW Expert 아카데미의 문제를 무단 복제하는 것을 금지합니다.

728x90

String으로 해결

N = input()
sum = 0

for s in N:
    sum += int(s)

print(sum)

int 타입으로 해결

N = int(input())
sum = 0

while(True):
    if (N == 0):
        break
    else:
        sum += N % 10
        N //= 10

print(sum)
728x90