2017-10-04 19 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)が発生します。 私はこのエラーがStrengthrun()return AGILITY, gamedata, strenghtwertにあると思います。ValueError:アンパックする値が多すぎます(予想2)PYTHON

何が問題なのですか?

正常に実行された最後の行は、同じ機能のstrenghtwert = int(input("STRENGTH: >>"))です。

+3

スタックトレース – acushner

+0

あなたは関数を呼び出しているどのように私たちを表示する私たちを見ます。 – Antimony

答えて

0

呼び出しの方法、それらの変数の種類、エラーのスタックトレース、または完全なコードなどの情報はありません。

このエラーは、通常、変数に割り当てるオブジェクトが不足しているか、変数よりも多くのオブジェクトを割り当てる複数割り当てのときに発生します。

たとえば、myfunction()が期待される2つのアイテムではなく3つのアイテムを返した場合、割り当てに必要な変数よりも多くのオブジェクトが存在します。

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)

関連する問題