2017-05-11 71 views
-1

我正在嘗試爲基於文本的冒險遊戲創建一個非常基本的戰鬥功能,我的問題是我特別減輕了關於這條線的錯誤。Python - 不能分配給函數調用?

random.choice(gold_dropped)+ =金

有問題的錯誤是語法錯誤:無法分配給函數調用錯誤,我難倒是什麼原因造成的問題,以及如何解決它。

任何反饋都將不勝感激。

在該錯誤所在的功能如下所示。

高清戰鬥():

enemy_health = (random.choice(random_enemy_Health)) 

enemy_attack = (random.choice(random_enemy_Attack)) 
print("You are fighting a" ,random.choice(enemies), "with an attack amount of" ,enemy_attack, "and a health amount of" ,enemy_health,".")  
while (enemy_health > 0): 
    enemy_attack - health; 

while (health > 0): 
    attack - enemy_health; 

if enemy_health == 0: 
    print("The enemy has been defeated!") 
    random.choice(gold_dropped) += gold 

if health == 0: 
    print("You have been defeated! Return back to the Hub and re-prepare yourself!") 
    hub_travel() 
+4

你可能是指'黃金+ = random.choice(gold_dropped)'。 – jasonharper

回答

0

與指令random.choice(gold_dropped)+ =金,你變 「黃金」 的價值添加的東西, 「不存在」(它必須是一個現有的變量,你不能指定某個函數的匿名結果)。這就是爲什麼Python解釋器抱怨。

你只需要使用(指令的正確性與Python 3.5下方勾選)中間變量:

if enemy_health == 0: 
    print("The enemy has been defeated!") 
    choice_of_gold_dropped = random.choice(gold_dropped) + gold 
... 
相關問題