whileループの一部であるリストに値を挿入しようとしていますが、最後の値を挿入するのではなく、前の値に置き換えていますので、リストには常に1つの値しかありません!値がそれらを交換しない追加し、ここに私のコードは次のとおりです。リストに値を挿入する
while X != 1:
resultList = [];
#extList = []
count += 1
if X % 2:
X = 3 * X + 1
elif not X % 2:
X = X // 2 #important to use double slash to have a integer division
print(X)
resultList.insert(count-1, X)
#print("the resultList is " + str(resultList))
#extList.extend(resultList)
print("The inputValue "+str(originalValue)+" took "+str(count)+" calculations to reach 1")
print (resultList)
任意のヘルプが
'resultList.insert(カウント-1を、X)を' '' –
resultList = [] '、おそらくあなたが書いている' while' – f5r5e5d
の内側にあってはならない 'resultList.append(X)でなければなりませんC++コードのようなPythonコード。強力なツールを使用してください。 – user1767754