0
print ("Input a binary number")

num1 = int(input() , 2)

print ("again prease")

num2 = int(input() , 2)

answer = num1 + num2

binaryanswer = bin(answer)[2:]

print ("That's " ,binaryanswer, " In behhieerryy")

input ("Press enter to end Program")          

again = raw_input

if again == 'Y':
    print("AGAAAINN!!")
    return

else:
    break

一切都在做它的工作,但我只能让程序重复自己。

4

2 回答 2

2

return并不意味着它会重新开始。您的程序中没有任何内容会导致它重复。将它放在一个函数中,如果用户按下“Y”,则再次调用该函数。

while 1:
    print ("Input a binary number")

    num1 = int(input() , 2)

    print ("again please")

    num2 = int(input() , 2)

    answer = num1 + num2

    binaryanswer = bin(answer)[2:]

    print ("That's " ,binaryanswer, " In behhieerryy")

    again = input ("Press enter to end Program")          



    if again != 'Y':
        break

    print("AGAAAINN!!")
于 2013-11-13T19:58:31.693 回答
0

不确定您要在这里做什么,但试试这个:

while True:
    print ("Input a binary number")
    num1 = int(input() , 2)
    print ("again prease")
    num2 = int(input() , 2)
    answer = num1 + num2
    binaryanswer = bin(answer)[2:]
    print ("That's " ,binaryanswer, " In behhieerryy")
    again = input("Press Y to try again or enter to end Program") 
    if again == 'Y':
        print("AGAAAINN!!")
    else:
        break
于 2013-11-13T20:10:09.373 回答