+ 1

Pls who can help me with the"Sum of consecutive numbers"challenge on python for beginners ?

30th Aug 2023, 6:21 PM
PELSKI
PELSKI - avatar
3 Answers
+ 6
PELSKI , here some hints how to get it solved: line 1: ok line 2: not required (i=N) > we need to run a for loop, to take the numbers generated by the range() function. keep in mind, that the upper bound of range() will not be included, so we have to add + 1 to the input value. > we have to sum up these numbers, so we need a variable that will take and build this accumulated sum. we can name it `total`. > build this sum in the loop body. > when the loop is finished, the `total` variable contains the requested result. > output it. test case: 5 -> 1 + 2 + 3 + 4 + 5 -> 15. >>> in general we should use meaningful variable names. also put spaces around operators.
30th Aug 2023, 7:15 PM
Lothar
Lothar - avatar
+ 8
PELSKI , before we can help you, we need to see your attempt first. > please save the code in plaground and link it here.
30th Aug 2023, 6:22 PM
Lothar
Lothar - avatar
+ 1
This is what I have tried: N = int(input()) #your code goes here i=N for u in range(N): print(i=i+N)
30th Aug 2023, 6:28 PM
PELSKI
PELSKI - avatar