0

What is the code to sum of consecutive numbers

Take a number N as input and output the sum of all numbers from 1 to N(including N)

14th Oct 2022, 7:31 AM
Iwinosa Aguebor
Iwinosa Aguebor - avatar
5 Antworten
+ 10
SoloProg , Amrita , STOP GIVING READY-MADE CODES TO THE ASKER, as long as he has not shown his attempt here. your behaviour is not seen as very helpful. may be it satifies your own ego, but it does NOT help the asker in his learning process. it is better to give hints and tips.
14th Oct 2022, 10:27 AM
Lothar
Lothar - avatar
+ 8
Iwinosa Aguebor , there are some issues to fix. see my comments in your code: N = int(input()) total = 0 # > better to use a new variable `total` instead of `N` O=list(range()) # > range() needs to get at least 1 argument. you can use the input value `N` here for i in o: # > variable `o` needs to be in upper case N=i+ 1 # > we need to use : total = total + i Print(N) # > print() has to be writren in lower case, argument should be `total` not `N`
15th Oct 2022, 11:20 AM
Lothar
Lothar - avatar
+ 1
Got it.. N = int(input()) o=list(range(0,N+1)) e = 0 for i in o: e+=i print(e)
17th Oct 2022, 4:45 PM
Iwinosa Aguebor
Iwinosa Aguebor - avatar
0
N = int(input()) print( sum(range(N+1)) ) print( sum(range(N),N) ) print( sum(range(N))+N )
14th Oct 2022, 7:47 AM
SoloProg
SoloProg - avatar
- 1
This is my try N = int(input()) O=list(range()) for i in o: N=i+1 Print(N)
14th Oct 2022, 11:57 AM
Iwinosa Aguebor
Iwinosa Aguebor - avatar