こんにちは、これは私が書いたコードです。ただし、毎回 0 を出力する変換された 2 進数を出力する代わりに、意図したとおりに機能します。誰かがこれを修正するのを手伝ってください。ありがとう
import time
import sys
n=0
while n!=1:
error=True
error1=True
print"\n"
print" *************************************"
print" *!Welcome to RBDC BinAdd Calculator!*"
print" *+++++++++++++1-Bin_Add+++++++++++++*"
print" *+++++++++++++++2-Exit++++++++++++++*"
print" *************************************"
print" Build 0.0.9 ALPHA\n"
while error:
try:
choice=input("Select a Option: ")
print "\n"
if choice >=3:
print"Please enter a number between 1-2."
error=False
except NameError:
print"Not a number. Please try again."
time.sleep(1)
except SyntaxError:
print"Not a number. Please try again."
time.sleep(1)
if choice ==1:
print"***You have selected Bin_Add.***\n"
while error1:
try:
bin2dec = raw_input("Please enter 1st binary number: ")
bin2dec2 = raw_input("Please enter 2nd 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)
time.sleep(1)
if False in [i == '0' or i == '1' for i in bin2dec]: # check if the number is in Binary for bin2dec
print "\n1st input is not Binary number. Please try again."
time.sleep(1)
else:
print "\n1st input is a Binary number"
time.sleep(1)
if False in [i == '0' or i == '1' for i in bin2dec]: # check if the number is in Binary for bin2dec2
print "\n2nd input is not Binary number. Please try again."
time.sleep(1)
else:
print "2nd input is a Binary number"
decnumstored=0
decnum = 0
for i in bin2dec:
decnum = decnum * 2 + int(i)
time.sleep(0.25)
decnum = decnumstored+int(decnum) #stores result of bin2dec2 in the decnumstored1 var.
decnumstored1=0
decnum1 = 0
for i in bin2dec2:
decnum = decnum1 * 2 + int(i)
time.sleep(0.25)
decnum = decnumstored1+int(decnum1) #stores result of bin2dec2 in the decnumstored1 var.
a=decnumstored+decnumstored1 ##adds the 2 variables and converts to binary
b = ''
b = str(a % 2) + b
a >>= 1
print "\n",str(b),"<<This is your answer!" ##
if choice==2:
endex=raw_input("\nDo you want to Exit? \nInput Y or N: ")
if endex == "N":
print "You have chosen to run this programme again...\n"
elif endex == "n":
print "You have chosen to run this programme again...\n"
else:
print "\nThank you for using RBDC Bin2Dec Converter \nGoodbye"
time.sleep(2)
break