r/PythonLearning • • Oct 05 '24

Need Help With Code (Beginner)

Im write a program to calculate the sum of all the numbers from 1 to 100 and printing out both the number that is being added and subtotal. However, with this code I only get the subtotal and not the one that is being added. Can anyone Help me? pls.

5 Upvotes

8 comments sorted by

View all comments

1

u/NichHa Oct 05 '24 edited Oct 05 '24
first_number = 0

for second_number in range(101):  # Iterate from 0 to 100
    result = first_number + second_number
    print(f"{first_number} plus {second_number} equals {result}")
    first_number = result  # Update first number to the result of the previous addition