重复功能不适用于列表 Python

Repeat function does not work with list Python

我写了一个骰子滚筒,可以生成随机数并将它们插入到列表中。然后打印列表中的每个迭代。

这在第一次运行时有效。但是,当询问 [​​=21=] 并选择 'y' 时,我收到 StopIteration 错误

不应该 Python 直接覆盖列表吗?

编辑:添加了更多代码

File "./test.py", line 159, in diceRoller
  sname = it1.next()
StopIteration




#imports

import random


#Stats start at 0

acc = 0
com = 0
con = 0
dex = 0
fig = 0
inl = 0
per = 0
str = 0
wil = 0


sname = 0
statList = ['Acc', 'Com', 'Con', 'Dex', 'Fig', 'Int', 'Per', 'Str', 'Wil']
it1 = iter(statList)



stat = []

def diceRoller():


  rollcount = 1
  index = 0
  print ' '
  print "Rolling 3 d6's for each stat"

  print fmtt.format(' ', 'Stat','Your rolls', 'Total', 'Stat value') 

  while rollcount < 10:

    die1 = random.randint(1,6)
    die2 = random.randint(1,6)
    die3 = random.randint(1,6)
    total = sum([die1,die2,die3])   

    rollcount += 1  


 (removed large if block - that sets bonus value)
  bonus = 4


for item in range(1):
  stat.append(bonus)

#print stat


#for i in range(1):
  sname = it1.next()


print fmt.format(' ', sname, die1, die2, die3, total, bonus)



  else:
    rroll = raw_input("Do you want to reroll? (y/n)")
    if rroll == 'y':
      diceRoller()
    else:
      statCalc()     

#### END DEF diceRoller

将statList作为参数传给diceRoller函数,然后放入

it1 = iter(statList)

在那个函数里面