Back to questions
JuniorTheoryCommon
What does the program print?
total = 0
for i in range(1, 10, 3):
total += i
print(total)12
- Expecting
22, as if10were included:rangestops beforestop, soitakes only1,4and7, and their sum is12. - Expecting
45, as if the step were ignored: the third argument3is the step, sorange(1, 10, 3)skips two numbers after each one.
- Which values does
range(10, 0, -3)produce? - How would you change the call so that
10is included in the sum?