2015-03-02 87 views
-2

我使用python 3.我已经写了一个代码。当我编译它时,我得到了一个EOF输入错误。请帮助我并描述我的问题的原因。对于使用记事本++的代码编辑,我试图用标准编译器和一些网站进行编译。 P.S.对不起,我的英语不好。我有一个简单的代码在Python和EOF错误

import random 
import os 
textinput = "" 
while textinput != "exit": 
    textinput = "" 
    textinput = input("What are you want to roll? (You can call help): ") 
    if textinput == "help": 
     print("/You choose Help/") 
     print("This is help") 
    elif textinput == "g": 
     print("/You choose GURPS/") 
     print(random.randint(1,6)+random.randint(1,6)+random.randint(1,6)) 
    elif textinput == "d": 
     print("/You choose D&D/") 
     print(random.randint(1,20)) 
    elif textinput == "%": 
     print("/You choose 1-100% roll/") 
     print(random.randint(1,100)) 
    else: 
     print("/You choose Custom/") 
     diceedges = int(0) 
     dices = int(0) 
     counter = int(0) 
     result = int(0) 
     generatedroll = int(0) 
     dices = int(input("Number of Dices: ")) 
     diceedges = int(input("Number of Dice Edges: ")) 
     while counter < dices: 
      generatedroll = random.randint(1,diceedges) 
      result = result + generatedroll 
      counter = counter + 1 
     print("= " + result) 
    print("") 
    textinput = input("/Press enter/") 
    os.system("cls") 

回答

0

在你的代码的唯一错误是,试图Concat的一个intstr,你需要转换结果的STR:

print("= " + result) # wrong 

print("= " + str(result)) # correct 

或者使用str.format

print("= {}".format(result)) 

您不需要将int作为int来投射,或者int(0)可以写成0。 另外python代码解释不编译。

我建议你检查出python practice book以熟悉基本

+0

@ ftvkyo2011,你可以,如果你需要解决一些答案下面发表评论。 – 2015-03-02 20:46:44