2015-03-02 45 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