Ask coding questions

← Back to all posts
Better Sum CodeHS. Please help :)
SimplyMiah

Hello Repel community,
I am stuck on a CodeHS question titled: Better Sum. Can you guys please help me with this, it means the world to me, thank you <3
Here is the problem :)

Write a program that asks the user for two numbers. Using a for loop, add all of the numbers from the first to the second.
For example if the first number is 6 and the second number is 8 the result is 21 (6 + 7 + 8).
Print out the results when you are finished.

Voters
SimplyMiah
Comments
hotnewtop
Coder100

Sure! What language?

JS

Python

C++

SimplyMiah

Oh nvm I get it thanks

SimplyMiah

Hey! :) For me, when I check my code, it tells me sume the numbers 100 to 200 and sum the numbers 0 to 1000 as well. How would I add this to my code?

Bookie0

@SimplyMiah well if you use the code I just shared with you below

it wouldnt need any change, it would work just fine ;)

Bookie0

hi there!

what language is this?

so first of all, to ask the user for 2 numbers you'll need an input. Then for the for loop, in python its for i in range(x) and replace x with the number you want or the variable you want.
you say the for loop has to add all the numbers from the first to second, so can maybe store the 1st number in a variable, say a and then increment a by one. Next add those two numbers together. do this until the 2nd number. To determine how many times the loop runs, you have to find out how many numbers between the 1st and the 2nd, so this can be achieved with a substraction.

then to print the results, use print.

Im assuming its in python, here is the brief program (spoiler alert)

So yea, if you need more help or if i was unclear, please tell me and I will try to help you ;)