Python 3.x TypeError:对象()不接受参数3
我是一个初学者,在尝试一个程序错误时:TypeError:object()不接受任何参数是经常发生的Python 3.x TypeError:对象()不接受参数3,python-3.x,Python 3.x,我是一个初学者,在尝试一个程序错误时:TypeError:object()不接受任何参数是经常发生的 next_output = True def start() : class Gate(object): """ class representing a gate. It can be any gate. """ def __init__(bit, *args): """ initialise the class """ b
next_output = True
def start() :
class Gate(object):
""" class representing a gate. It can be any gate. """
def __init__(bit, *args):
""" initialise the class """
bit.input = args
bit.output = None
def logic(bit):
""" the intelligence to be performed """
raise NotImplementedError
def output(bit):
""" the output of the gate """
bit.logic()
return bit.output
a = int(input("Enter the first input: "))
b = int(input("Enter the second input: "))
class AndGate(Gate):
""" class representing AND gate """
def logic(bit):
bit.output = bit.input[0] and bit.input[0]
return bit.output
class NotGate(Gate):
""" class representing NOT gate """
def logic(bit):
bit.output = not bit.input[0]
return bit.output
class NandGate(AndGate,NotGate):
def logic(bit):
bit.flag = AndGate.logic(bit)
Gate.__init__(bit,bit.flag)
bit.output = NotGate.logic(bit)
return bit.output
n = NandGate(a,b).logic()
print(int(n))
while next_output :
start()
在运行时,行中发生错误
n=与非门(a,b).logic()
def logic(self):
说明它正在自己工作class NandGate(Gate):
def logic(self):
anded = AndGate(self.input).logic() # calculate the and'd values
notted = NotGate(anded).logic() # not them
return notted
这不仅比让一个对象两者兼而有之更清晰,而且代码的重用更整洁,调用特定的uu init_u_u时跳过的麻烦更少def output(bit):
""" the output of the gate """
return bit.logic()
class Gate():
def __init__():
# definitions
class NotGate(Gate):
# more definitions
# functional flow of program
a = int(input("Enter the first input: "))
b = int(input("Enter the second input: "))
n = NandGate(a,b).logic()
print(int(n))
def logic(self):
说明它正在自己工作class NandGate(Gate):
def logic(self):
anded = AndGate(self.input).logic() # calculate the and'd values
notted = NotGate(anded).logic() # not them
return notted
这不仅比让一个对象两者兼而有之更清晰,而且代码的重用更整洁,调用特定的uu init_u_u时跳过的麻烦更少def output(bit):
""" the output of the gate """
return bit.logic()
class Gate():
def __init__():
# definitions
class NotGate(Gate):
# more definitions
# functional flow of program
a = int(input("Enter the first input: "))
b = int(input("Enter the second input: "))
n = NandGate(a,b).logic()
print(int(n))
对于第5点和第6点,完全有可能错误只是来自一个被声明为Gate的一部分,而不是作为运行时程序的一部分的全局变量。您输入的代码在我的计算机上运行得非常好。如果不直接使用任何一个类的方法,为什么要从
AndGate
和NotGate
继承NandGate
?只需从门继承
。但用于定义操作。应该提到所有需要的门。获得的输出是回溯(最后一次调用):文件“C:\Users\Rhea M Pradeep\Documents\python\trail.py”,第54行,在start()文件“C:\Users\Rhea M Pradeep\Documents\python\trail.py”,第49行,在start n=NandGate中(Gate).logic()类型错误:object()不带任何参数您发布的代码中没有这行代码…您放置的代码在我的计算机上运行良好。如果您不直接使用任何一个类的方法,为什么要从和继承NandGate
和NotGate
?只需从Gate继承即可。但是为了定义一个操作,所有的门都是必需的应该提到的是,获得的输出是回溯(最后一次调用):文件“C:\Users\Rhea M Pradeep\Documents\python\trail.py”,第54行,在start()文件“C:\Users\Rhea M Pradeep\Documents\python\trail.py”,第49行,在start n=NandGate(Gate).logic()中TypeError:object()不接受您发布的代码中没有的行的参数…问题只在循环时出现问题只在循环时出现问题