我写了一个新函数,当我执行它时,我得到一个错误:
<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.")当我执行read_grades()函数或GRADES命令时,会出现此错误。
对于那些标记了这个问题的人:我做了一些搜索,我没有找到那篇文章,现在我读了它,我不明白答案
发布于 2016-06-27 01:07:57
这不是运行时错误,您打印了一个函数
print(read_grades)试着调用它
read_grades() 你可以在这里覆盖你的函数
read_grades = save.read()因此,建议不要使用与函数名冲突的变量名
https://stackoverflow.com/questions/38041011
复制相似问题