2016-10-04 57 views
-2

我一直在嘗試使用Python的微薄知識來創建一個基於回合的RPG,但我因爲與這段代碼的問題:Python 3.5.1 - 一年多的代碼需要很多建議

pattack="" 
pnote="" 
pdmg=0 
ppriority=0 

selectmove=int(input("Select move number 1-4")) 

if selectmove==1: 
    pattack="Fire Ball" 
    pdmg=pdmg+150 
    ppriority=ppriority+60 
    pnote="A firey ball is shot at the enemy" 
elif selectmove==2: 
    pattack="Thunder Bolt" 
    pdmg=pdmg+100 
    ppriority=ppriority+80 
    pnote="A bolt of electricity is shot at the enemy" 
elif selectmove==3: 
    pattack="Leaf Wirlwind" 
    pdmg=pdmg+175 
    ppriority=ppriority+50 
    pnote="A Wirlwind of razor sharp leaves is sent to the enemy" 
elif selectmove==4: 
    pattack="Icicle Shot" 
    pdmg=pdmg+75 
    ppriority=ppriority+100 
    pnote="A sharp icicle is shot at the enemy" 
pdmg=int(pdmg) 
ppriority=int(ppriority) 
print(int("Used the move "+pattack+"\nDealt "+str(pdmg)+" Damage\nHas a priority of "+str(ppriority)+"\nMove description: *NOT FINAL*\n"+pnote+" "))` 

所有我曾經得到的是這樣的錯誤消息:

`Traceback (most recent call last): 
    File "C:\Users\Alberto\Desktop\My Test RPG\Battle System Idea\An Idea I have.py", line 30, in <module> 
    print(int("Used the move "+pattack+"\nDealt "+str(pdmg)+" Damage\nHas a priority of "+str(ppriority)+"\nMove description: *NOT FINAL*\n"+pnote+" ")) 
ValueError: invalid literal for int() with base 10: 'Used the move Fire Ball\nDealt 150 Damage\nHas a priority of 60\nMove description: *NOT FINAL*\nA firey ball is shot at the enemy " 
+7

您正在將整個字符串轉換爲最後一行中的整數。我不認爲你打算這麼做,對吧? – Terry

+4

你會期待什麼號碼?使用移動火球\ n重要的150點傷害\ n優先級爲60 \ n移動描述:*不是最後的* \ n一個火球向敵人射擊「'是」 –

+1

我沒有得到爲什麼你試圖將所有可能的*轉換爲int。'pdmg = int(pdmg)'當'pdmg'已經**了** int'。 –

回答

1
print(int("Used the move "+pattack+"\nDealt "+str(pdmg)+" Damage\nHas a priority of "+str(ppriority)+"\nMove description: *NOT FINAL*\n"+pnote+" ")) 

這行應該是:

print("Used the move "+pattack+"\nDealt "+str(pdmg)+" Damage\nHas a priority of "+str(ppriority)+"\nMove description: *NOT FINAL*\n"+pnote+" ") 

您不希望將整個字符串轉換爲int

0

在您最後的print行中,您不需要調用int():它僅用於將值轉換爲整數,該字符串不是。