协助ISU

2024-09-30 04:37:20 发布

您现在位置:Python中文网/ 问答频道 /正文

在为一个类编写一些代码时,它出现了这个错误,我不知道如何修复它,因为我个人看不到它所解决的任何问题

traceback (most recent call last):
  File "C:\Users\Daniel Benotti\Desktop\School\Benotti_Daniel student Ed loop with functions.py", line 50, in 
    main()
  File "C:\Users\Daniel Benotti\Desktop\School\Benotti_Daniel student Ed loop with functions.py", line 9, in main
    TotCurr, TotCe = loop(TotCurr, TotCe, again)
  File "C:\Users\Daniel Benotti\Desktop\School\Benotti_Daniel student Ed loop with functions.py", line 21, in loop
    TotCurr, TotCe, studType = calc(studNum, TotCurr, TotCe)
  File "C:\Users\Daniel Benotti\Desktop\School\Benotti_Daniel student Ed loop with functions.py", line 34, in calc
    if studNum > STUD_NUMBER:
TypeError: '>' not supported between instances of 'str' and 'int'`enter code here`

这是下面的代码

STUD_NUMBER = 2500

def main():
    TotCurr, TotCe, again = init()
    TotCurr, TotCe = loop(TotCurr, TotCe, again)
    dispTot(TotCurr, TotCe)

def init():
    TotCurr = 0
    TotCe = 0
    again = "Y"
    return TotCurr, TotCe, again

def loop(TotCurr, TotCe, again):
    while again.upper() == "Y":
        firstName, lastName, studNum = getInput()
        TotCurr, TotCe, studType = calc(studNum, TotCurr, TotCe)
        dispDetail(studType)
        again = input("Do you want to add another student record? (Y/N): ")
        print()
    return TotCurr, TotCe

def getInput():
    firstName = input("please enter students first name: ")
    lastName = input("please enter students last name: ")
    studNum = input("please enter the student ID number: ")
    return firstName, lastName, studNum

def calc(studNum, TotCurr, TotCe):
    if studNum > STUD_NUMBER:
        studType = "Curriculum"
        TotCurr += 1
    else:
        studType = "Continuing Education"
        TotCe +=1
    return TotCurr, TotCe, studType

    def dispdetail(studType):
        print("This student is currently in the", studType, 'course')
        print()

    def dispTot(TotCurr, TotCe):
        print("Total students in Cuuriculum course", TotCurr)
        print("Total students in Continuing education course", TotCe)

main()
enter code here

Tags: inloopdefusersstudentfileprintenter

热门问题