Aug-12-2017, 01:30 PM
I am trying to examine every sum of three numbers from a single list
So for example if the list was 1,2 I want to examine 1=1+1+1 and 1+1+2 and 1+2+2 and 2+2+2
In the code below:
The variable I am examining is threesum
The list is three_digit_squares[]
Whenever I run the code it gives me "index out of range" error on the line starting "threesum ="
So for example if the list was 1,2 I want to examine 1=1+1+1 and 1+1+2 and 1+2+2 and 2+2+2
In the code below:
The variable I am examining is threesum
The list is three_digit_squares[]
Whenever I run the code it gives me "index out of range" error on the line starting "threesum ="
three_digit_squares = [] for i in range (1,4): three_digit_squares.extend([i]) for i in three_digit_squares: for j in three_digit_squares: for k in three_digit_squares: threesum = three_digit_squares[i] + three_digit_squares[j] + three_digit_squares[k] if threesum == 4: print "yes"