I'm trying to write a program to add up the numbers from 1 to n. I've managed to get it to print the numbers several times but not to add them all. It keeps on just adding two of the numbers.
My 1st attempt is:
def problem1_3(n):
my_sum = 0
while my_sum <= n:
my_sum = my_sum + (my_sum + 1)
print()
print(my_sum)
How can I fix this problem?
For the recursive version of this question, see Recursive function to calculate sum of 1 to n?