我使用python 3.我已经在其上编写了代码。当我编译它时,我得到了 EOF输入错误。请帮助我并描述我的问题的原因。对于代码编辑,我使用notepad ++,并尝试使用标准编译器和某些站点进行编译。 附:抱歉我的英语不好。
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 :(得分:0)
您的代码中唯一的错误是尝试将int
连接到str
,您需要将结果转换为str:
print("= " + result) # wrong
print("= " + str(result)) # correct
或使用str.format
:
print("= {}".format(result))
您不需要将int转换为int int(0)
只能写成0
。
python代码也被解释为未编译。
我建议您查看python practice book以熟悉基础知识