Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 陷入外部文件python的读取循环_Python 3.x_Infinite Loop - Fatal编程技术网

Python 3.x 陷入外部文件python的读取循环

Python 3.x 陷入外部文件python的读取循环,python-3.x,infinite-loop,Python 3.x,Infinite Loop,这是一个无止境的循环。我有一个文件,里面有25个随机生成的数字 但是文件只是循环。我哪里出错了 这是一门课,但我只是想知道为什么它会循环,而不是我作业的答案 要循环文件中的每一行,需要在每次循环运行时更新line变量。 因此,您应该将循环更改为:(同时仍保留line=numberFile.readline()!) 否则,循环将检查同一行。一次又一次…提示:line=numberFile.readline()只调用一次。你应该把那一行也放到while循环中。#我把它放在这里:while line!

这是一个无止境的循环。我有一个文件,里面有25个随机生成的数字 但是文件只是循环。我哪里出错了


这是一门课,但我只是想知道为什么它会循环,而不是我作业的答案

要循环文件中的每一行,需要在每次循环运行时更新line变量。 因此,您应该将循环更改为:(同时仍保留
line=numberFile.readline()
!)


否则,循环将检查同一行。一次又一次…

提示:
line=numberFile.readline()
只调用一次。你应该把那一行也放到
while
循环中。#我把它放在这里:while line!=“”:line=numberFile.readline()value=int(line)if value>=highVal:highVal=value#并且我在GetMaximum value=int(line)ValueError中得到第21行:以10为基数的int()的文本无效:“”
def main():
    getLargest()



def getLargest():
    global line, value, highVal, numberFile
    numberFile = open('numbers.dat', 'r') 
    print("Lets find the largest number!")
    highVal = 0
    line = numberFile.readline()

    while line != "":
        value = int(line)
        if value >= highVal:
           highVal = value

    numberFile.close()   
    print("Highest value: ", highVal)


main()
    while line != "":
        value = int(line)
        if value >= highVal:
           highVal = value
        line = numberFile.readline()