私のwhileループinfを取得できません。getClasses関数は、終了時に終了することができません。 getNumとcounterの両方が整数として設定されます。私もwhile True
とif文を使って、それが助けになるかどうかを調べようとしましたが、無限ループになります。私はこれが単純な問題であることを知っていますが、私が間違っていることが何であるかは分かりません。助けてください。Unending While Pythonのループ
def getNum():
while True:
try:
num = int(raw_input("How many classes do you have:\n")) #Asks the user for the number of classes he/she has.
break
except:
print("Input must be a number")
return num
def getGrades(): #Gets the grades from the user
counter2 = 1
global grades
if counter2 <= getNum: #If the 2nd counter is less than or equa to the number of classes...
while True:
try:
grades = int(raw_input("What is the grade for class %s:\n" %counter2)) #Asks the user what their grades are for 'counter' class.
counter2 += 1 #...increase the 2nd counter by 1
break
except:
print("Input must be a number")
return grades
def getClasses(): #Gets the user's classes
counter = 1
getNum()
while counter <= getNum: #If the counter is less than or equal to the number of classes...
classes = str(raw_input("Class %s is what:\n" %counter)) #Asks the user what their 'counter' class is.
subjects[classes] = getGrades()
counter += 1 #...increase the counter by 1
return subjects
それが終了することになっていますか? getNumとは何ですか? –
'counter2 <= getNum'と' getNum() '?整数と関数の両方にすることはできません...このコードはまったく機能しない可能性があります。 – tdelaney
getNumとは何ですか? –