小编NoO*_*One的帖子

Python函数没有运行,解释器没有给出任何错误

我是Python的新手,并且我正在为一个类做一个程序的问题.main()和create_file工作,但是当它到达read_file时,解释器就在那里.该程序正在运行但没有任何事情发生.

答案可能很简单,但我看不出来.在此先感谢您的帮助.

我正在使用IDLE(Python和IDLE v.3.5.2)

这是代码:

import random

FILENAME = "randomNumbers.txt"

def create_file(userNum):

    #Create and open the randomNumbers.txt file
    randomOutput = open(FILENAME, 'w')

    #Generate random numbers and write them to the file
    for num in range(userNum):
        num = random.randint(1, 500)
        randomOutput.write(str(num) + '\n')

    #Confirm data written
    print("Data written to file.")

    #Close the file
    randomOutput.close()

def read_file():

    #Open the random number file
    randomInput = open(FILENAME, 'r')

    #Declare variables
    entry = randomInput.readline()
    count = 0
    total = 0

    #Check for eof, read in …
Run Code Online (Sandbox Code Playgroud)

python function

2
推荐指数
1
解决办法
38
查看次数

标签 统计

function ×1

python ×1