⭕풀이:
numbers = list(range(1, 10_001)) #1부터 10,000까지 들어있는 리스트를 만든다.
remove_list = [] #for반복문을 통해 만들 생성자 숫자들 list = numbers에서 삭제할 숫자들 list
for num in numbers : #ex) num=850
for n in str(num): #ex) n = str(num) = "8", "5", "0"
num += int(n) #ex) 850 = 850 + 8 + 5
if num <= 10000: #10,000보다 작거나 같은 생성자를 제외한 셀프 넘버를 출력해야 하기 때문에 생성자 또한 10,000보다 작거나 같은 조건문을 붙인다.
remove_list.append(num) #생성자 숫자들 list에 생성자들을 넣는다.
for remove_num in set(remove_list): #set을 통해 생성자 숫자들 중에 중복되는 숫자들을 제거한 뒤 remove_num이라는 변수에 넣어 반복한다.
numbers.remove(remove_num) #1부터 10,000까지 있는 숫자들 중 생성자 숫자들을 제거해 numbers 리스트에 셀프 넘버들만을 남겨둔다.
for self_num in numbers: #셀프 넘버만을 남겨둔 numbers리스트를 self_num이라는 변수에 대입해 반복해라.
print(self_num)
⭕풀이:
def hansu(num): #hansu라는 이름으로 다음 내용을 함수로 만들자.
hansu_cnt = 0
for i in range(1, num+1): #1에서 num으로 넣은 입력값만큼 i에 대입해 반복해라.
num_list = list(map(int, str(i))) #ex)i=110, num_list = ['1', '1', '0']이다.
if i < 100: #i가 100미만이면 모두 한수이다.(실제로 그러해서 굳이 1~99까지 한수인지 아닌지 알아낼 필요가 없다.)
hansu_cnt += 1
elif num_list[0] - num_list[1] == num_list[1] - num_list[2]: #ex)i=110, num_list = ['1', '1', '0']이므로 1-1 = 1-0
hansu_cnt += 1 #성립된다면 hansu_cnt = hansu_cnt + 1
return hansu_cnt #성립되지 않는다면 hansu_cnt = hansu_cnt
num = int(input())
print(hansu(num))