Skip to main content
 首页 » 编程设计

python之EOF 错误 python 3

2025年04月02日13xing901022

我在 python 3 中不断收到 EOF 错误。这是我的代码

num = float(input()) #servings 
p = float(input()) #people 
a2 = float(input()) 
b2 = float(input()) 
c2 = float(input()) 
d2 = float(input()) 
e2 = float(input()) 
f2 = float(input()) 
g2 = float(input()) 
h2 = float(input()) 
i2 = float(input()) 
a1 = a2 / num 
b1 = b2 / num 
c1 = c2 / num 
d1 = d2 / num 
e1 = e2 / num 
f1 = f2 / num 
g1 = g2 / num 
h1 = h2 / num 
i1 = i2 / num 
a = a1 * p 
b = b1 * p 
c = c1 * p 
d = d1 * p 
e = e1 * p 
f = f1 * p 
g = g1 * p 
h = h1 * p 
i = i1 * p 
lis = str(a)+ str(b)+ str(c)+ str(d)+ str(e)+ str(f)+ str(g)+ str(h)+   str(i) 
print (lis) #8 14 1 1 6 2 1 2 .5 2 

错误在第 11 行。如果我删除第 11 行及其所有代码,它会在第 10 行、第 9 行、第 8 行等处给出错误。

请您参考如下方法:

代码工作正常,直到您给出 11 个输入值,因为有 11 个输入语句。当您没有提供足够的输入时,会发生 EOF 错误。我假设最后一行的评论 是您的输入并且它只有 10 个值。我认为这就是 EOF 错误的原因。