r/pythonhelp • u/[deleted] • Oct 16 '20
Help
If someone chose the number 3, how would I make a code that chooses all the positive integers from 1 to n (3), and displays the sum of the numbers? So for example 3, 1+2+3=6(sum)
4
Upvotes
1
u/HobbesTheDireTiger Oct 16 '20
You could create a program that accepts an input or parameter of n and uses a for loop to add each consecutive integer in the range of the n that you chose to a general variable that you could call sum that you could then return. I'm new to python myself so I don't know if this is the best way but I was able to do it like that.