我想添加 2 个二进制数,但是我的程序无法正常工作。请查看我的代码并在任何错误中告诉我。谢谢。这是代码:
import time
n=0
while n!=1:
error1=True
while error1:
try:
bin2dec = raw_input("Please enter a binary number: ")
bin2dec2 = raw_input("Please enter a binary number: ")
error1=False
except NameError:
print"Enter a Binary number. Please try again.\n"
time.sleep(0.5)
except SyntaxError:
print"Enter a Binary number. Please try again.\n"
time.sleep(0.5)
decnum=0
for i in bin2dec:
decnum = decnum * 2 + int(i)
decnum2=0
for i in bin2dec2:
decnum2 = decnum2 * 2 + int(i)
dectotal=decnum+decnum2
b = ''
b = str(dectotal % 2) + b
dectotal >>= 1
print b,
print"<<This is your answer"