問題: ユーザー入力に基づいて 2 つの整数を計算します。最初の整数は繰り返し 2 倍になり、2 番目の整数は 2 で除算されます。各ステップで、2 番目の数値が奇数の場合、2 番目の数値がゼロになるまで、最初の数値の現在の値をそれ自体に追加します。
コードが完全に実行されていないようで、無限ループが発生します。何が間違っていますか? 私はpython 2.7.3を使用しています
##
## ALGORITHM:
## 1. Get two whole numbers from user (numA and numB).
## 2. If user enters negative number for numB convert to positive.
## 3. Print numA and numB.
## 4. Check if numB is odd if True add numA to numA.& divide numB by 2 using int division.
## Print statement showing new numA and numB values.
## 5. Repeat steps 3 and 4 until numB is 0 or negative value. enter code here
## 6. Prompt user to restart or terminate? y = restart n = terminate
##
## ERROR HANDLING:
## None
##
## OTHER COMMENTS:
## None
##################################################################
done = False
while not done:
numA = input("Enter first integer: ") # 1. Get two whole numbers from user (A and B)
numB = input("Enter second integer: ") # 1. Get two whole numbers from user (A and B)
if numB < 0:
abs(numB) # 2. If user enters negative number for B convert to positive
print'A = ',+ numA,' ','B = ',+ numB
def isodd(numB):
return numB & 1 and True or False
while numB & 1 == True:
print'B is odd, add',+numA,'to product to get',+numA,\
'A = ',+ numA,' ','B = ',+numB,\
'A = ',+ numA+numA,' ','B = ',+ numB//2
else:
print'result is positive',\
'Final product: ', +numA
input = raw_input("Would you like to Start over? Y/N : ")
if input == "N":
done = True