Skip to content

Python 503 連加計算

Python TQC

題目說明:

請撰寫一程式,讓使用者輸入兩個整數,接著呼叫函式compute(),此函式接收兩個參數a、b,並回傳從a連加到b的和。

範例輸入
33
66

範例輸出

1683

Solution

1
2
3
4
5
6
def compute(a, b):
    SUM = 0
    for i in range(a, b+1):
        SUM += i
    return SUM
print(compute(eval(input()), eval(input())))

Last update : 13 novembre 2024
Created : 13 novembre 2024

Comments

Comments