问题:根据用户输入计算两个整数,第一个整数重复加倍,第二个整数除以二。在每一步,如果第二个数字是奇数,则将第一个数字的当前值添加到自身,直到第二个数字为零。
我的代码似乎没有完全运行,我得到一个无限循环我做错了什么?我正在使用 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