小编zwe*_*rg4的帖子

IndexError:列表分配索引超出范围 Python 3

有人知道为什么我在这段代码中得到一个 IndexError 吗?

            global gegner
            global gegnerhp
            gegner = []
            gegberhp = []



            for i in range(1,anzahlgegner):
                random = randint(1,5)
                if random == 1:
                    gegner[i] = "goblin"
                    gegnerhp[i] = randint(10,50)
                elif random == 2:
                    gegner[i] = "ghost"
                    gegnerhp[i] = randint(10,50)
                elif random == 3:
                    gegner[i] = "hound"
                    gegnerhp[i] = randint(10,50)
                elif random == 4:
                    gegner[i] = "wolf"                        #LINE 147
                    gegnerhp[i] = randint(10,50)
                elif random == 5:
                    gegner[i] = "goblin"
                    gegnerhp[i] = randint(10, 50)
                print("* {0} with {1} HP".format(gegner[i]),gegnerhp[i])
Run Code Online (Sandbox Code Playgroud)

例如,当随机数为 4 …

python arrays pycharm python-3.x index-error

5
推荐指数
1
解决办法
2万
查看次数

带有指针变量的地址数组

我尝试将地址存储在变量中.这个地址应该像一个数组.我从输入中获得的每个新数据都应该保存在变量+ index的地址中.

int RF = 0x15; // address array
int R2 = 0 ; // index
*(RF + R2) = 100;
Run Code Online (Sandbox Code Playgroud)

但是当我编译它时,我收到此错误:

错误:一元'*'的无效类型参数(有'int')

有谁有想法为什么?

c gcc pointers

0
推荐指数
1
解决办法
82
查看次数

ValueError:太多值无法解包(预期2)PYTHON

class Strength(State):
    def run(self, gamedata):
        print("You have 100 points to assign to your character.\n Start now to assign those Points to your characters strength, agility, speed and defense.")
        strenghtwert = int(input("STRENGTH: >>"))
        return AGILITY, gamedata, strenghtwert

    def next(self, next_state):
        if next_state == AGILITY:
            return CreatePlayer.agility

class Agility(State):
    def run(self, gamedata,strenghtwert):
        agilitywert = int(input("AGILITY: >>"))
        return SPEED, gamedata, strenghtwert, agilitywert

    def next(self, next_state):
        if next_state == SPEED:
            return CreatePlayer.speed
Run Code Online (Sandbox Code Playgroud)

执行此操作时,出现错误:ValueError: too many values to unpack (expected 2)。我认为错误是return AGILITY, …

python state-machine pycharm python-3.x

-1
推荐指数
1
解决办法
1万
查看次数

标签 统计

pycharm ×2

python ×2

python-3.x ×2

arrays ×1

c ×1

gcc ×1

index-error ×1

pointers ×1

state-machine ×1