내 정답
num=[]
temp=0
while(temp!=-1):
temp=int(input())
num.append(temp)
i=0
for i in num:
sumlist=[]
j=1
while(j<i): #i까지 약수 search
if(i%j==0):
sumlist.append(j)
j+=1
if sum(sumlist)==i:
string = " + "
list_string = map(str, sumlist) #string.join 쓰기 앞서 int->str 변환
string_list = string.join(list_string) #string으로 list concat
print("%d =" % i, string_list)
elif i == -1:
exit
else:
print("%d is NOT perfect." %i)
total 23줄
'코딩놀이: python C C++' 카테고리의 다른 글
프로그래머스 lv2: 오픈채팅방(dictionary, in) (0) | 2022.06.14 |
---|---|
프로그래머스 lv2: 스택/큐 주식가격, bool list 만들기 (0) | 2022.05.21 |
프로그래머스 LV2: 더맵게 python, heapq 사용법 (0) | 2022.05.21 |
[2696] 중앙값 구하기, 변수에 변수 넣기(?) (0) | 2022.05.19 |
[10828] 알고리즘 - 스택 (0) | 2022.05.19 |