Latest web development tutorials

Python includes exercises 69

Python 100 Li Python 100 Li

Title: There are n personal cordons Arranging the order. It started from the first reported that the number (from 1-3 count off), where the report of 3 people exit the circle, the last remaining original asking who the first few numbers.

Program Analysis: None.

Source Code:

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

if __name__ == '__main__':
    nmax = 50
    n = int(raw_input('请输入总人数:'))
    num = []
    for i in range(n):
        num.append(i + 1)

    i = 0
    k = 0
    m = 0

    while m < n - 1:
        if num[i] != 0 : k += 1
        if k == 3:
            num[i] = 0
            k = 0
            m += 1
        i += 1
        if i == n : i = 0

    i = 0
    while num[i] == 0: i += 1
    print num[i]

Implementation of the above code, the output:

$ python test.py 
请输入总人数:34
10

Python 100 Li Python 100 Li