该程序修改了“myclass”类的对象_x 和_y,但我没有将它作为参数传递给函数try_block。对象如何被修改?
class AddSub:
def _init_(self): #how do default parameters work?
self._x, _y
def set_x(self, num):
self._x = num
def set_y(self, num):
self._y = num
def add(self):
return self._x + self._y
def sub(self):
return self._x - self._y
def try_block():
try:
ch = int(input("type 1 to add, and 2 to subtract: "))
myclass.set_x(int(input("enter an x value: "))) #how does myclass get modifed?
myclass.set_y(int(input("enter a y value: ")))
return ch
except ValueError:
print("Invalid entry.")
ch = try_block()
return ch
myclass = AddSub()
choice = try_block()
if choice == 1:
print(myclass.add())
elif choice == 2:
print(myclass.sub())