0
我写了一个新的功能,当我执行它,我得到一个错误:Python的<在0X功能>输出
<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命令时发生错误。
对于那些谁标志着这个问题:我做了一些搜索和我没有找到该职位,现在,我读它,我不明白的答案
是啊,我不得不改变返回打印但是谢谢你这么多,另外一个问题,你如何独立,不带空格成一个字符串字符串与昏迷和空格或数组? – 1234filip
@ 1234filip关于分割字符串的问题与当前的问题无关!如果您在全面搜索后无法找到答案,请提出一个新问题,但您需要对此进行更好的解释,并用一些典型的输入和预期输出来说明问题。 –
好吧,我会在网上搜索KK – 1234filip