【发布时间】:2015-12-04 18:45:59
【问题描述】:
x, y = raw_input("Enter 2 numbers separated by a space.").split()
answer = 0
#Enter the 2 numbers to be calculated.
print "You have selected, A = "+ x + " and B = " + y + "."
while int(y):
if (not int(y) % 2 == 0):
# this checks if y is even or odd
answer = int(answer) + int(x)
print "A = " + str(x) + " and B = " + str(y) + "."
print "B is odd so we'll add A to the total."
print "The running total is " + str(answer) + "."
else: (int(y) % 2 == 0)
print "A = " + str(x) + " and B = " + str(y) + "."
print "B is even, so we'll ignore that number."
x = int(x) * 2
y = int(y) / 2
print "The product is " + str(answer) + "."
while True:
a = raw_input("Would you like to make another calculation? Y or N")
if str(a) == "Y" or str(a) == "y":
continue
if str(a) == "N" or str(a) == "n":
print "Thank you have a nice day!"
break
else:
print "Invalid entry. Ending program."
break
如果输入“Y”或“y”来表示“您要进行另一个计算吗?”,我正试图让我的程序返回到顶部 while 循环。到目前为止,我所拥有的让我回到了底部的 while 循环。有什么帮助吗?谢谢!
【问题讨论】:
标签: python while-loop continue