在我的代码中,当读取一行时,EOF:EOF

2024-05-19 01:45:46 发布

您现在位置:Python中文网/ 问答频道 /正文

Traceback (most recent call last):
  File "Solution.py", line 11, in <module>
    line = input()
EOFError: EOF when reading a line
def afff(line):
    if('2' in line):
        return True
    return False

nam = input()
n = nam.split()[0]
m = nam.split()[1]
count = 0
for i in range(int(m)):
    line = input()
    if afff(line):
        count+=1

print(count)

任务:

学生阿曼做关于数据库的家庭作业。他需要建立一个大学生数据库,并能够回答这个问题——有多少学生没有通过考试。当Arman用SQL完成任务时,您需要编写一个程序,根据学生、学科和成绩列表,给出答案——有多少学生完成了这一课程

输入格式

第一行包含两个整数:N-学生数量和M-学科数量。接下来,输入N行,每行有M个数字——学生在M个学科中获得的分数

约束条件

(1<;=N,M<;=1000)学生的分数可以在2到5之间

输出格式

打印一个整数-通过课程但未获得平分的学生人数

样本输入0

3 4
5 3 4 4
5 5 5 4
3 4 2 3

样本输出0

二,


Tags: in数据库inputreturnif格式countline
1条回答
网友
1楼 · 发布于 2024-05-19 01:45:46

Ok, from the description, you need to read N lines with M numbers in each. Instead, you're trying to read M lines. Change range(int(m)) to range(int(n)) - Tom Karzes

range(int(m))更改为range(int(n))

整个代码:

def afff(line):
    if('2' in line):
        return True
    return False

nam = input()
n = nam.split()[0]
m = nam.split()[1]
count = 0
for i in range(int(n)):
    line = input()
    if afff(line):
        count+=1

print(count)

相关问题 更多 >

    热门问题