2017-10-04 182 views
-3
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 

當我執行此操作時,出現錯誤:ValueError: too many values to unpack (expected 2)。 我認爲錯誤在return AGILITY, gamedata, strenghtwertrun()StrengthValueError:需要解壓縮的值太多(預計爲2)PYTHON

任何想法是什麼問題?

最後一行成功執行的代碼是strenghtwert = int(input("STRENGTH: >>"))

+3

我們展示的堆棧跟蹤 – acushner

+0

向我們展示你是如何調用該函數。 – Antimony

回答

0

沒有更多的信息,如調用的方式,某些變量的類型,錯誤的堆棧跟蹤或完整的代碼。

此錯誤通常發生在多次賦值過程中,您沒有足夠的對象分配給變量,或者您有更多的對象要分配給變量。

例如,如果myfunction()返回一個帶有三個項目的迭代而不是預期的兩個,那麼您將擁有比指定給變量所需的變量更多的對象。

def myfunction(): 
    return 'stuff', 'and', 'junk' 

stuff, junk = myfunction() 

Traceback (most recent call last): File "/test.py", line 72, in <module> stuff, junk = myfunction() ValueError: too many values to unpack (expected 2)

它解決,你必須比對象更多的變量的其他方式。

def myfunction(): 
    return 'stuff' 

stuff, junk = myfunction() 

Traceback (most recent call last): File "/test.py", line 72, in <module> stuff, junk = myfunction() ValueError: too many values to unpack (expected 2)

相關問題