Does it calculate progression correctly? (Tested, by sheer luck it does, but you should fix it) Why don't you use if operation < len(progress_set)?
Python has 0-based index arrays, what it means is
array = [1, 2, 3]
array[0] //1
array[2] //3
range(0, 10) transformed to a list and first element (0th index) is 0 (can be done in one line progression = [i * 5 for i in range(0, 10)]) Let's say your input is "3", your array is [0, 5, 10, 15, 20, 25, 30, 35, 40, 45] you calculate (5 + 15) * 3 / 2 = 30. It is only works out if first element is 0. Because "3" is actually 4th element of the array, which is 15. Well... it's actually pretty hard to explain... change range(0, 10) to range(1, 10) and check arithmetic progression sum
Thx, but I actually set start of the range to 0 on purpose, since I know that Python uses zero-based indexing...? I can find the specific number based on its position, just like in the formula an = a1 + d(n-1)
progress_set has 10 elements with index 0 through 9, thus there is no element 10, so operation needs to be below 10. You can use integer division // and get rid of mapping to int instead of using real division / on the last line. You probably also want operation to be positive.
2
u/Money_Ad_5277 6d ago edited 6d ago
Does it calculate progression correctly? (Tested, by sheer luck it does, but you should fix it)
Why don't you use
if operation < len(progress_set)?Python has 0-based index arrays, what it means is
range(0, 10) transformed to a list and first element (0th index) is 0 (can be done in one line
progression = [i * 5 for i in range(0, 10)])Let's say your input is "3", your array is [0, 5, 10, 15, 20, 25, 30, 35, 40, 45] you calculate (5 + 15) * 3 / 2 = 30. It is only works out if first element is 0. Because "3" is actually 4th element of the array, which is 15.
Well... it's actually pretty hard to explain... change
range(0, 10)torange(1, 10)and check arithmetic progression sumEdit: sheAr luck...
1
u/AlexMTBDude 6d ago
1
u/Educational-Paper-75 3d ago
progress_set has 10 elements with index 0 through 9, thus there is no element 10, so operation needs to be below 10. You can use integer division // and get rid of mapping to int instead of using real division / on the last line. You probably also want operation to be positive.