Python 尝试将用户输入用作参数时发生EOF错误

Python 尝试将用户输入用作参数时发生EOF错误,python,Python,我刚开始使用python,我正在尝试创建一个简单的Ricky计算器 def ricky_adds(x,y): num1 = x num2 = y if num1 >= 10: num1 = input("No. I said A number, not multiple numbers dummy. Try again :") if num1 < 0: num1 = input("Wow you're dumb, I s

我刚开始使用python,我正在尝试创建一个简单的Ricky计算器

def ricky_adds(x,y):
    num1 = x
    num2 = y
    if num1 >= 10:
        num1 = input("No. I said A number, not multiple numbers dummy. Try again :")
    if num1 < 0:
        num1 = input("Wow you're dumb, I said a number, not some imaginary shit. Try again :")
    num2 = y
    if num2 >= 10:
        num2 = input("No. I said A number, not multiple numbers dummy. Try again :")
    if num2 < 0:
        num2 = input("Wow you're dumb, I said a number, not some imaginary shit. Try again :")

    result = num1 + num2
    return result

ricky_adds(input("Gimmie a number. :"), input("Smokes, let's go. Another number, c'mon. :"))
def ricky_添加(x,y):
num1=x
num2=y
如果num1>=10:
num1=输入(“不,我说的是一个数字,不是多个数字。请重试:”)
如果num1<0:
num1=input(“哇,你真傻,我说的是数字,不是想象中的狗屎。再试一次:”)
num2=y
如果num2>=10:
num2=输入(“不,我说的是一个数字,不是多个数字。请重试:”)
如果num2<0:
num2=input(“哇,你真傻,我说的是数字,不是想象中的狗屎。再试一次:”)
结果=num1+num2
返回结果
ricky_加上(输入(“给我一个数字”)、输入(“吸烟,我们走。另一个数字,来吧”))
但是得到这个错误

Gimmie a number. :Smokes, let's go. Another number, c'mon. :
Traceback (most recent call last): 
  File "..\Playground\", line 17, in <module> 
    ricky_adds(input("Gimmie a number. :"), input("Smokes, let's go. Another number, c'mon. :")) 
EOFError: EOF when reading a line 
Gimmie一个数字:抽烟,我们走吧。另一个号码,来吧
回溯(最近一次呼叫最后一次):
文件“.\playerd\”,第17行,在
ricky_加上(输入(“给我一个数字”)、输入(“吸烟,我们走。另一个数字,来吧”))
EOF:读取一行时的EOF

我想不出如何纠正这个错误。我可以不使用“input()”获取用户参数输入吗?

好的,谢谢大家迄今为止的帮助。这就是我现在拥有的:

def main():
    x = int(input("Gimmie a number. :"))
    y = int(input("Smokes, let's go. Another number, c'mon. :"))

    print("Here's the answer. See, Julian? I out smarted your stupid books and did that arthritis in my head and got " + str(ricky_adds(x,y)))

def ricky_adds(x,y):
    num1 = x
    num2 = y
    lessthanzeroerror = "Wow you're dumb, I said a number, not some imaginary shit. Try again :"
    greaterthantenerror = "No. I said A number, not multiple numbers dummy. Try again :"
    if num1 >= 10:
        num1 = int(input(greaterthantenerror + ":"))
    elif num1 < 0:
        num1 = int(input(lessthanzeroerror + ":"))
    if num2 >= 10:
        num2 = int(input(greaterthantenerror + ":"))
    elif num2 < 0:
        num2 = int(input(lessthanzeroerror + ":"))

    result = num1 + num2
    return result

main() 
致:


它成功了。谢谢大家提出的指导性问题。

你需要重新思考你的逻辑。。数字可以>=10,不能是多个数字。 考虑使用<代码>嵌套if语句< /代码>。
def ricky_adds(x,y):
    num1 = x
    num2 = y

    if num1 >= 10:
        num1 = input("No. I said A number, not multiple numbers dummy. Try again :") # what happens after this statement? what is the purpse of this input. You need to nest the statements to continue in a logical manner.
    if num1 < 0:
        num1 = input("Wow you're dumb, I said a number, not some imaginary shit. Try again :")

    if num2 >= 10:
        num2 = input("No. I said A number, not multiple numbers dummy. Try again :")
    if num2 < 0:
        num2 = input("Wow you're dumb, I said a number, not some imaginary shit. Try again :")

您是在输入一个数字,还是只需按
Enter
<如果
input()
没有接收到任何内容,则会弹出code>eoferor。您的代码工作正常(除了您没有使用从
ricky_添加的
返回的值执行任何操作)。在此处使用您的代码,并将[5][Enter][3][Enter]作为关键输入,我没有收到任何错误我收到一个TypeError错误,但在Python3中没有EOF错误,在Python2中没有错误。您为输入输入了什么数据?字符串应该模拟字符的思维和说话方式。这个角色是《拖车公园男孩》中的瑞奇,“多重数字”应该是瑞奇对多重数字感知的一种表现。谢谢你的建议,我会尝试一下。这是我现在的密码。我仍然没有找到最好的方法来压缩我的if语句,但是我清理了那里的内容,希望这会带来顿悟。
print(ricky_adds(input("Gimmie a number. :"), input("Smokes, let's go. Another number, c'mon. :")))
def ricky_adds(x,y):
    num1 = x
    num2 = y

    if num1 >= 10:
        num1 = input("No. I said A number, not multiple numbers dummy. Try again :") # what happens after this statement? what is the purpse of this input. You need to nest the statements to continue in a logical manner.
    if num1 < 0:
        num1 = input("Wow you're dumb, I said a number, not some imaginary shit. Try again :")

    if num2 >= 10:
        num2 = input("No. I said A number, not multiple numbers dummy. Try again :")
    if num2 < 0:
        num2 = input("Wow you're dumb, I said a number, not some imaginary shit. Try again :")
if (num1>= 10 or num2 >= 10):
    print("you have enter a number greater then 10")
    data = input("try again")
    if......
elif (num1 < 0 or num2 < 0):
    print("you number is less than 0")

    return (num1 + num2)
def main():
    x = int(input("Gimmie a number. :"))
    y = int(input("Smokes, let's go. Another number, c'mon. :"))

ricky_adds(x,y)