I have been stuck on the consecutive numbers project in python for beginners and I was wondering if I could get help on it. Do I have to create a variable that adds all the numbers in range?
4/12/2021 12:30:46 PM
tirth patel9 Answers
New AnswerI tried this N = int(input()) #your code goes here sum = 0 for i in range(1, N+1): sum += i print(sum) But it still shows me the list instead of the last value, I tried indexing it but since it is an integer I am getting an error message
t=0#declaring variable and assign initial value zero to it for e in range(1,5): # calculate values from 1 to 4 t+=e # adding t and e print(t)
No in the above code you will put print(sum) inside for loop but you will put it outside for loop. just run this below code then it will give output https://code.sololearn.com/cPE8igoIzUBH/?ref=app
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message