from traillets.config.application import logging
def AND(a,b):
A = a * b
return A
def OR(a,b):
if a == 1:
if b == 1:
A = 1
else:
A = 0
def NOT(a):
if a == 1:
A = 0
if a == 0:
A = 1
return A
def ha(a,b):
A1 = OR(a,b)
keta = AND(a,b)
A2 = NOT (keta)
A = AND (A1, A2)
return A, keta
deffa(a,b,x):
A1,keta1 = ha(a,b)
A,keta2 = ha(A1,x)
keta=OR (keta1, keta2)
return A, keta
a = input ("binary number")
b = input ("the binary plus")
k=len(a)
k = k - 1
x = 0
goukei=""
while k>=0:
ha = int(a(k))
fa = int(b(k))
A,keta=fa(a,b,x)
goukei=str(A)+goukei
x = keta
k = k - 1
goukei=str(x)+goukei
print(a, "+", b, "=", gookei)
I'd like to do a binary calculation using half-add and full-add. Below the last while syntax,
TypeError Traceback (most recent call last)
<ipython-input-30-1544c3673a72>in<module>
39goukei=""
40 while k>=0:
--- >41 ha = int(a(k))
42 fa = int(b(k))
43 A, keta = fa(a, b, x)
TypeError: 'str' object is not callable
appears, and the process does not proceed.Please let me know
python
As a whole, there are about three major mistakes.
Extraction of Elements
while k>=0:
ha = int(a(k))
fa = int(b(k))
A,keta=fa(a,b,x)
a[k]
, b[k]
if you want to take it out
ha
, fa
are used as function names, so they are overwritten.Should be a different variable name fa
should be the previous "extracted value" instead of a
, b
© 2025 OneMinuteCode. All rights reserved.