# Python exercises

Exercises: one hundred people, respectively, from 1 to 100. Now a man has a gun from the first shot, every shot a skip one, until a complete. Then the man alive inside again shot first, spacing of a re shoot one, is the last living is a few people that out of one hundred of them? See who can write simple.

Started by Pauline at February 02, 2016 - 7:48 AM

She left.:

#!/usr/bin/python

people_list = []
dead_man = 0
shoot = 'no'

for i in range(0,100):
people_list.append("alive")

while dead_man <100:
for point in range(0,100):
if people_list[point] == 'alive' and shoot == 'yes':
people_list[point] = 'dead'
dead_man += 1
shoot = 'no'
if dead_man == 100:
print point+1
elif people_list[point] == 'alive' and shoot == 'no':
shoot = 'yes'

Posted by Pauline at February 10, 2016 - 8:35 AM

I am learning to write a short, look:
1. #!/usr/bin/python

2. people_list = []
3. for i in range(0,100):
4. people_list.append(i)

5. while len(people_list) > 1:
6. for i in range(0, 100):
7. if i >= len(people_list):
8. break
9. people_list.pop(i)

10. print people_list

Posted by Gilbert at February 15, 2016 - 8:43 AM

Ask question to ask why not directly use the people_list assignment
people_list=range(100)

Posted by Jean at February 18, 2016 - 8:51 AM

I only know a little fur, beginner, do not know can write so, according to LZ code change

Posted by Gilbert at March 02, 2016 - 9:27 AM

Your answer and my answer is not the same ~ your result is 63, I was 73

Posted by Pauline at March 16, 2016 - 10:20 AM

1. #!/usr/bin/python

2. people_list = range(100)

3. while len(people_list) > 1:
4. for i in range(100):
5. if i >= len(people_list):
6. break
7. people_list.pop(i)

8. print people_list
9. print people_list
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99]
[3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95, 99]
[7, 15, 23, 31, 39, 47, 55, 63, 71, 79, 87, 95]
[15, 31, 47, 63, 79, 95]
[31, 63, 95]
[63]
[63]

Seems right, from 63 the beginning of 0

Posted by Gilbert at March 27, 2016 - 10:38 AM

I have vegetables than you I think that assignment is not good

Posted by Jean at March 31, 2016 - 11:06 AM

Yes, I just wrote that after the implementation of LZ is 63 from second began to shoot

Posted by Jean at April 01, 2016 - 11:56 AM

person_list = []
n = 0
while True:
if len(person_list) == 1:
break
else:
person_list = [x for x in range(2**n,101,2**n)]
n += 1
print person_list

I was 64, and the standard answer

Posted by Hugh at April 08, 2016 - 12:37 PM

The first shot and then, my answer is 72

Posted by Pauline at April 15, 2016 - 1:23 PM

a=range(1,101)
while len(a) <1:
a = a[0::2] //Shot second start
# a= a[1::2] //Shot the first

print a

Do not know right, ha ha

Posted by Dennis at April 29, 2016 - 1:26 PM

64.
1. #-*- coding:utf-8 -*-

2. def who_survive(max):
3. alive =range(1, max+1)
4. while len(alive) > 1:
5. alive = alive[1::2]
6. return alive[0]

7. if __name__ == "__main__":
8. survive = who_survive(100)
9. print "The last man who survived is", survive

Posted by Yolanda at April 30, 2016 - 1:57 PM

Exercises: one hundred people, respectively, from 1 to 100. Now a man has a gun from the first shot, every shot a skip one, until a complete. Then the man alive inside again shot first, spacing of a re shoot one, is the last living is a few people that out of one hundred of them? See who can write simple. # -*- coding: cp936 -*-

My code def diyilun(range1):
t=range(1,101)
for i in range(1,range1,2):
if i>=len(t):
break
t.pop(i)
print i
diyilun(101)
This is my 67

Posted by Everley at May 01, 2016 - 2:44 PM

The 64 is, I had less of a link, each wheel starts, re setup: the first shot.

#!/usr/bin/python

people_list = []
dead_man = 0

for i in range(0,100):
people_list.append("alive")

while dead_man <100:
shoot = 'yes'
for point in range(0,100):
if people_list[point] == 'alive' and shoot == 'yes':
people_list[point] = 'dead'
dead_man += 1
shoot = 'no'
if dead_man == 100:
print point+1
elif people_list[point] == 'alive' and shoot == 'no':
shoot = 'yes'

Posted by Pauline at May 07, 2016 - 3:01 PM

I came to learn the level of food,

Posted by Everley at May 15, 2016 - 3:49 PM

Ideas of bovine X, worship

Posted by Allen at January 01, 2017 - 4:47 AM

1. person = []
2. for i in range(1,101):
3. person.append(i)

4. for i in person:
5. if i % 2 != 0:
6. person.remove(i)
7. while i > 0:
8. for i in person:
9. person.remove(i)
10. i += 2
11. if len(person) == 1:
12. break

13. print (person)
I was 64, the answer.?

Posted by Randal at January 02, 2017 - 7:24 AM

Hello, is this sentence is what mean?
1. __name__ == "__main__"
Why not see definition?

Posted by Randal at January 10, 2017 - 5:47 AM

The main function of this code is mainly for the python file can run independently, can also be used as a module into other documents. When importing to other script file, the main code is not performed.

See:
The use of Python on the name main
The python module of the __name__

Posted by Yolanda at January 12, 2017 - 6:40 AM