首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python < 0x>输出的函数

Python < 0x>输出的函数
EN

Stack Overflow用户
提问于 2016-06-27 01:05:54
回答 1查看 18K关注 0票数 1

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

<function read_grades at 0x000001F69E0FC8C8>

好的,下面是我的代码:

代码语言:javascript
复制
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.")

当我执行read_grades()函数或GRADES命令时,会出现此错误。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-27 01:07:57

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

代码语言:javascript
复制
print(read_grades)

试着调用它

代码语言:javascript
复制
read_grades() 

你可以在这里覆盖你的函数

代码语言:javascript
复制
read_grades = save.read()

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

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38041011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档