What you will learn
Iterate over a range and maintain an accumulator.
Understand the concept
range(1, 6) produces 1 through 5 because the stop value is excluded.
Practise
Read the stop value from input and calculate the total.
Iterate over a range and maintain an accumulator.
range(1, 6) produces 1 through 5 because the stop value is excluded.
Read the stop value from input and calculate the total.
Experiment with the program below. Your code and input are sent to the selected compiler only when you run it.
Tab indents · Shift+Tab unindents · Esc then Tab leaves the editor · Ctrl/Cmd+Enter runs · Ctrl/Cmd+S saves a draft
Changes save automatically to your account.
No input required.Expected output for the original program
15
Output will appear here.
Educational simulation — object identities and execution steps are illustrative.