2016-10-04 30 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():它仅用于将值转换为整数,该字符串不是。