Good day, I solve the problem on the site


Write an effective program that will cyclically shift the given array by k elements to the right. Additional arrays and recursion do not use.

Specifications Input The program first receives the values ​​n100 - the number of elements in the array and k100. The next line of input data contains the array elements themselves - integers that do not exceed 30,000 in absolute value.


n, m = input().split() n = int(n) k = int(m) array = input().split() for i in range(len(array)): array[i] = int(array[i]) array = array[-k:] + array[:-k] print(array) 

They write: Wrong output format. What is my joint?

  • one
    A description of the desired output format should be given directly in the question. You should also show what your code is currently outputting (a literal example right in the question). - jfs

1 answer 1

You have an error code

 n, m = input().split() 

No initialization of variable m

 n = int(n) k = int(m) 

Cannot convert array to type int

Additional arrays and recursion do not use.

You are using array

  • one
    If the input contains a space, then split () returns more than one value (try entering a pair of numbers). That is, m also has a value or an exception is thrown. And accordingly, n not a "array" of strings, but simply one of two strings. - jfs