Python <函数在0x>输出

123*_*lip 1 python runtime-error python-3.x

我写了一个新函数,当我执行它时,我收到一个错误:

<function read_grades at 0x000001F69E0FC8C8>

好的,这是我的代码:

def add(x, y):
    z = x / y * 100
    return z

def calc_grade(perc):
    if perc < 50:
        return "1"
    if perc <  60:
        return "2"
    if perc < 75:
        return "3"
    if perc < 90:
        return "4"
    if perc >= 90:
        return "5"

def calc_command():
    num1 = input("Input your points: ")
    num2 = input("Input maximum points: ")
    num3 = add(float(num1), float(num2))
    grade = calc_grade(num3)
    print("This is your result:", str(num3) + "%")
    print("Your grade:", grade)
    save = open("grades.txt", "r")
    read_grades = save.read()
    save = open("grades.txt", "w")
    save.write(read_grades + grade)
    save.close()

def read_grades():
    save = open("grades.txt", "r")
    read_grades = save.read()
    grades = read_grades.split()
    save.close()
    return grades

while True:
    command = input("Input your command: ")
    if command == "CALC":
        calc_command()
    elif command == "EXIT":
        break
    elif command == "GRADES":
        print(read_grades)
    elif command == "HELP":
        print("These are the commands:\nCALC - Calculates your grade and writes in the file.\nEXIT - Exits the program.\nGRADES - Reads your previous grades.\nHELP - This command. It helps you.")
    else:
        print("You inputed an invalid command. Type HELP for help.")
Run Code Online (Sandbox Code Playgroud)

执行read_grades()函数或GRADES命令时会发生此错误.

对于那些标记这个问题的人:我做了一些搜索,我没有找到那个帖子,现在我读了它,我不明白答案

cri*_*007 6

这不是运行时错误,您打印了一个函数

print(read_grades)
Run Code Online (Sandbox Code Playgroud)

请尝试调用它

read_grades() 
Run Code Online (Sandbox Code Playgroud)

你在这里覆盖你的功能

read_grades = save.read()
Run Code Online (Sandbox Code Playgroud)

因此,建议不要使用与函数名冲突的变量名