Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+5 votes
asked in CSC201 Spring 2021 by (1 point)

3 Answers

+1 vote

Hi Adam,

To sum the numbers in a for loop statement, you will first want to set your initial variable to something before the loop. Since this is regarding addition, you will set the initial variable equal to zero.
Ex. theSum = 0

Next, in the for loop statement, you will want to take that variable equal to itself plus another variable. When you set it equal to itself, it will accumulate the sum and add the new variable as well.
Ex. theSum = theSum + newVariable.

Let me know if this makes sense! I hope it can help.

answered by (1 point)
0

got it! thank you.

+1 vote

I assume that you are asking about the 1st question of RP6
You can set a variable to display the sum of the number. You should set the variable to equal 0 before the for loop

After that, the variable should equal to itself, add the number that the users input

answered by (1 point)
0

Thank you!

0 votes

Hi there,
you need to set a variable such as x = 0, then in the loop you should write something like for I in range (4):
x = x + 5
By doing so, your x will be updated with the value of i.

answered by (1 point)
...