1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | def get_sum(start, end): # start, end¸¦ ¸Å°³º¯¼ö·ÎÇÏ¿© ÀÎÀÚ¸¦ ¹Þ´Â´Ù s = 0 for i in range(start, end + 1): # startºÎÅÍ end±îÁö Á¤¼öÀÇ ÇÕÀ» ±¸ÇÔ s += i return s # startºÎÅÍ end±îÁö ¼öÀÇ ÇÕÀ» ¹ÝȯÇÑ´Ù print(get_sum(1, 10)) # 1¿¡¼ 10±îÁö Á¤¼öÀÇ ÇÕ 55¸¦ Ãâ·ÂÇÑ´Ù x = get_sum(1, 10) # 1°ú 10ÀÌ ÀÎÀÚ°¡ µÈ´Ù. print('x =', x) y = get_sum(1, 20) # 1°ú 20ÀÌ ÀÎÀÚ°¡ µÈ´Ù. print('y =', y) | cs |