Latest web development tutorials

Pythonは演習68と、

Pythonの100リー Pythonの100リー

タイトル:整数nがあり 、それが戻っ各数列メートルの位置の前に移動し、最終的には何よりもメートルのm個の番号になります

プログラム解析:なし。

ソースコード:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    n = int(raw_input('the total number is:\n'))
    m = int(raw_input('back m:\n'))

    def move(array,n,m):
        array_end = array[n - 1]
        for i in range(n - 1,-1,- 1):
            array[i] = array[i - 1]
        array[0] = array_end
        m -= 1
        if m > 0:move(array,n,m)
        
    number = []
    for i in range(n):
        number.append(int(raw_input('input a number:\n')))
    print 'orignal number:',number

    move(number,n,m)

    print 'after moved:',number

上の例の出力は、次のとおりです。

the total number is:
8
back m:
5
input a number:
2
input a number:
8
input a number:
6
input a number:
1
input a number:
78
input a number:
45
input a number:
34
input a number:
2
orignal number: [2, 8, 6, 1, 78, 45, 34, 2]
after moved: [1, 78, 45, 34, 2, 2, 8, 6]

Pythonの100リー Pythonの100リー