当我运行这个程序时:(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
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'。。。
此外,这是一个更大的程序的一部分,基于猜测谁的游戏。。。
有人能告诉我怎么解决这个问题吗?
泰铢