当我运行这个程序时:(python 3.3.1)
import random
import time
from random import randrange
print(' ')
print('I am thinking of a person...')
time.sleep(1)
print('He or she belongs to this group of people:')
people = 'Alice Elise Jack Jill Ricardo David Jane Sacha Thomas'.split()
loop = 0
while loop != 6:
group = []
person = randrange(0, len(people))
personName = people[person]
int(person)
group.append(personName)
del people[person]
loop = loop + 1
我有时会收到此错误消息:
Traceback (most recent call last):
File "C:\Users\user\Python\wsda.py", line 132, in <module>
person = randrange(0, len(people))
File "C:\Python33\lib\random.py", line 192, in randrange
raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0,0, 0)
基本上我希望它从变量'people'中获取6个随机名称并将其添加到变量'group'中......
这也是基于猜测谁游戏的更大程序的一部分......有人可以告诉我如何解决这个问题吗?谢谢