So I know how to do this exercise (https://www.codecademy.com/courses/python-beginner-nzzVa/3/4?curriculum_id=4f89dab3d788890003000096) using just
for x in n:
However, I would like to try to pass this exercise by utilizing the range.
Could someone please let me know what am I still missing?
The most confusing part of my code might be
The idea was to get the last number in the list. For instance, if n = [0,3,6]. Then len(n) is 3. 3-1 is 2. n is 6 which is the last number in the list. Dif is the absolute value of (first item in list - second item in the list); therefore, 0-3 = -3 and absolute value of -3 is just 3. Thus, 6+3 is 9 and 6 will be now included in the output.
n = [3, 5, 7] def total(numbers): result = 0 dif = abs(n-n) for x in range(n, n[(len(n)-1)]+dif,dif): result += x return result