강의

멘토링

커뮤니티

Inflearn Community Q&A

sja97074102's profile image
sja97074102

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

4. Correction of representative value error

자릿수의 합

Written on

·

264

0

자릿수의 합 문제에서 자릿수의 합을 구할 때

아래와 같이 함수를 구하는데, 이때  while 문 대신 if 문으로 작성 했을 시 답이 다른 이유에 대해서 알고 싶습니다.

def digit_sum(x):
sum=0
while x>0:
sum+=x%10
x=x//10
return sum
python코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

while문 대신 if문이라는 게 무슨말인지 모르겠네요. 답이 다르게 나오는 코드를 보여주세요. 아니면 제가 동영상의 몇 분 지점에 그렇게 얘기했다라고 적어주시던지요.

sja97074102's profile image
sja97074102

asked

Ask a question