2013-12-10 93 views
-4

誰能告訴我爲什麼這有一個語法錯誤?我已經運行了這個確切的代碼,它完美的工作。 強文本中的行是Python告訴我語法錯誤的地方。感謝大家!解釋此語法錯誤

import random 

count = 0 
while count < 10: 

    attackerLV = 20 
    attackerST = 20 
    attackerSK = 20 
    baseAtkPwr = 20 
    attackPWR = ((random.randint(85,100) * (baseAtkPwr + attackerLV + attackerST + attackerSK)) // 100 

    **defenderLV = 20** 
    defenderCON = 20 
    defenderSKa = 20 
    baseDefPwr = 20 
    defensePWR = (((random.randint(85,100)) * (baseDefPwr + defenderLV + defenderCON + defenderSKa)) // 4) // 100 

    damage = attackPWR - defensePWR 

    if damage <= 1: 
     damage = 1 

    print(str(attackPWR)) 
    print(str(defensePWR)) 
    print(str(damage)) 
    print() 

    count = count + 1 
+5

這個問題似乎是題外話,因爲它是關於看上一個微不足道的語法錯誤。 –

+0

Python顯示它認爲錯誤出現在一個小'^'的位置。如果這沒有幫助,最好的辦法是將你的大量表達式分解成單獨的行中的單獨的子表達式,將中間結果存儲到可以替換爲主表達式的變量中。那麼它會變得明顯,你錯了什麼地方。 – abarnert

+0

[「SyntaxError:invalid syntax」on v​​alid statement]可能重複(http://stackoverflow.com/questions/19472645/syntaxerror-invalid-syntax-on-valid-statement) – SethMMorton

回答

5

您在這裏錯過了一個括號:

attackPWR = ((random.randint(85,100) * (baseAtkPwr + attackerLV + attackerST + attackerSK)) // 100