[Python] SWEA 2025번 : N줄 덧셈

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

     

    SW Expert Academy

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

    swexpertacademy.com

    1부터 주어진 숫자만큼 모두 더한 값을 출력하시오.
    단, 주어질 숫자는 10000을 넘지 않는다.

    [예제]
    주어진 숫자가 10 일 경우 출력해야 할 정답은,
    1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55

     

    [풀이]

    a = int(input("입력: "))
    
    result = 0
    for i in range (0,a+1):
        result += i
    print(f"합계: {result}")

    댓글