有人知道为什么我在这段代码中得到一个 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 …
我尝试将地址存储在变量中.这个地址应该像一个数组.我从输入中获得的每个新数据都应该保存在变量+ index的地址中.
int RF = 0x15; // address array
int R2 = 0 ; // index
*(RF + R2) = 100;
Run Code Online (Sandbox Code Playgroud)
但是当我编译它时,我收到此错误:
错误:一元'*'的无效类型参数(有'int')
有谁有想法为什么?
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, …