Repeat函数不适用于list Python

Repeat函数不适用于list Python,python,list,function,repeat,Python,List,Function,Repeat,我已经写了一个骰子滚轮,可以生成随机数并将其插入列表。然后打印列表中的每个迭代 这在第一次运行时起作用。但是,当被问到是否要重新滚动时?选择“y”会得到一个StopIteration错误 Python不应该覆盖列表吗 编辑:添加了更多代码 File "./test.py", line 159, in diceRoller sname = it1.next() StopIteration #imports import random #Stats start at 0 acc

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

这在第一次运行时起作用。但是,当被问到是否要重新滚动时?选择“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作为参数发送到Dicerroller函数,然后放置

it1 = iter(statList)

在该函数内部

那么,在这段代码中,it1是什么呢?您的意思是再次调用函数吗?因为这里没有重复。我从你的标题中想,你可能正在使用,或者当迭代器的值用完时,应该抛出一个异常。。这里没有足够的信息来回答您的问题。对不起,it1指的是我的列表it1=iterstatList的迭代,但基本上我想要的是函数根据答案重新运行。因此,如果我选择“y”,它会再次运行函数并生成一组新的数字。在range1中,i的处理方式是什么?这只会循环一次。为什么不让代码完全没有循环呢?谢谢!这比我预想的要容易得多。