Python 3,初学者错误

时间:2017-04-23 23:19:53

标签: python-3.x syntax-error

我必须输入每个学生的班级名称,教师姓名,姓名/字母等级。将信息写入文件,然后替换每个等级的金额。我在第19,55和41行出错。第19行给出错误类型'str'对象不可调用。有人可以帮忙吗?这就是我所拥有的:

Grades = open("ClassNameGrades.txt", "w")

count = 0
A=0
B=0
C=0
D=0
F=0

def gradeInput(count,numStudents,A,B,C,D,F):
    while count<numStudents:
        studentName=input("Enter name of student - ")
        Grades.write(studentName("\n"))       <<<Error#1
        studentGrade=input("Enter student letter grade - ", ).upper()
        Grades.write(studentGrade("\n"))
        count=count+1
        if studentGrade =="A":
            A+=1
        elif studentGrade =="B":
            B+=1
        elif studentGrade =="C":
            C+=1
        elif studentGrade =="D":
            D+=1
        elif studentGrade =="F":
            F+=1
    return count,numStudents,A,B,C,D,F

def main():
    Grades.write=input("Enter name of class - ",)
    Grades.write= input("Enter name of faculty - ")
    numStudents =int(float(input("Enter the amount of students - ")))
    gradeInput(count,numStudents,A,B,C,D,F)    <<Error#2
    print("Students who got an A = ", A)
    print("Students who got an B = ", B)
    print("Students who got an C = ", C)
    print("Students who got an D = ", D)
    print("Students who got an F = ", F)

main()   <<Error#3

Grades.close()

1 个答案:

答案 0 :(得分:0)

对于第一个:而不是Grades.write(studentGrade("\n")),它将是Grades.write(studentGrade + "\n")

前者是一个函数调用,但是你将它输入一个字符串。

后者合并两个字符串,因此如果学生成绩为“A”,则会写出“A \ n”,即A,然后是换行符。