It is necessary to make a two-dimensional list of n * n with numbers that doubled (1,2,4,8,16 and so on) and output that number according to the coordinates entered by the user, I made a list generator, but I can not display.

n=int(input()) s=int(input()) g=int(input()) a = [[0]*n for i in range(n)] counter = 1 for x in range(n): for y in range(n): a[x][y] = counter counter += counter print(a) print(a[s][g]) 

Input data:

 8 2 7 

8- field length 2, 7 - coordinates respectively Weekend:

 32768 

I have the conclusion: 8388608 I understand that the account will be entered from 0, but I can’t think of how to properly deduce

  • one
    print(a[s-1][g-1]) ? By the way the correct conclusion should be: 16384 - MaxU
  • I tried, but the output should be 32768, the problem says - Double Mid
  • one
    then you fill the array incorrectly - start filling with 1 , and not with 0 - MaxU
  • one
    If we assume that the matrix is ​​filled correctly, then the correct answer is: print(a[s-1][g-1]) - MaxU
  • one
    range returns values ​​from 0 to 7, and you probably represent an array as from 1 to 8, so you correctly return the value 8388608, since in the written code, in your understanding, you output 3 lines, column 8 - Komdosh

1 answer 1

print([s - 1][g - 1]) - if you make such a conclusion, then your input (8, 2, 7) will give output 16384. And what you entered yields such a result for an obvious reason. After all, the counting starts from 0, therefore setting s = 2 is just the same as turning to the third list. Therefore, you have such a conclusion. If you use this output print([s - 1][g - 1]) , and the input data (8,2,8), then you will get the desired result. In your case, specify the input data as follows (8, 1, 7).