MIT OpenCourseware Sc 6.00で質問を試みました。 質問は6、9、20パックのマクナゲットと合計数の組み合わせを見つける方法です。このコードを実行するときTypeError: 'NoneType'オブジェクトはMIT Opencourseの割り当てに対して反復できません
def Mac():
totalnumber = int (input('Enter total number of McNuggets'))
num20,num6,num9= solve2(totalnumber)
def solve2(numtotal): #define a new function to find and print multiple answers
solutionfound = False # set up a variable to check if the solution is found
for num20 in range (0,numtotal//20 + 1):
for num9 in range (0,numtotal//9 +1):
num6 = (numtotal-num20*20-num9*9)//6
if num6 > 0:
checknum = num20*20+num9*9+num6*6
if checknum == numtotal:
print ('The number of 6-pack is', num6)
print ('The number of 9-pack is', num9)
print ('The number of 20-pack is', num20)
solutionfound = True # change the initial variable to True
if not solutionfound:
print ('There is no solution')
しかし、それは常に表示: は現在、私のコードがある
TypeError: 'NoneType' object is not iterable
コード内のどの行が例外を発生させていますか? – elethan
'solve2'は' None'を返します、pythonはそれを解凍しようとしています。 – TheClonerx
@Nurzhan編集時にPythonコード内の空白を変更することはお勧めしません。 – MYGz