在我的类DemoOperator中,结果显示AttributeError:DemoOperator实例没有属性' optr_jumlah'。请告诉我编码中的错误和修改内容。
#program latian
class DemoOperator:
def __init__(self):
#input data x dan y
x = raw_input("Masukkan x : ")
y = raw_input("Masukkan y : ")
self.optr_jumlah(int(x), int(y))
self.optr_kurang(int(x), int(y))
self.optr_kali(int(x), int(y))
self.optr_bagi(int(x), int(y))
self.optr_modulus(int(x), int(y))
def optr_jumlah(self, a, b):
a += b
print "x += y hasilnya ",a
def optr_kurang(self, a, b):
a -= b
print "x -= y hasilnya ",a
def optr_kali(self, a, b):
a *= b
print "x *= y hasilnya ",a
def optr_bagi(self, a, b):
a /= b
print "x /= y hasilnya ",a
def optr_modulus(self, a, b):
a %= b
print "x %= y hasilnya ",a
if __name__ == '__main__':
aplikasi = DemoOperator()
这是从上面的代码中显示的一些错误:
Traceback (most recent call last):
File "E:\Kuliah\python\demoOperator.py", line 34, in <module>
aplikasi = DemoOperator()
File "E:\Kuliah\python\demoOperator.py", line 7, in __init__
self.optr_jumlah(int(x), int(y))
AttributeError: DemoOperator instance has no attribute 'optr_jumlah'
感谢您回答我的问题。