重复功能不适用于列表Python

时间:2015-08-14 17:31:27

标签: 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 = 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

1 个答案:

答案 0 :(得分:0)

将statList作为参数发送到diceRoller函数,然后放入

it1 = iter(statList)

在该函数内