class MyClass(object): """docstring for MyClass""" def __init__(self, arg): super(MyClass, self).__init__() self.arg = arg def ipdate_val(self, x): self.val = x def recieve_val(self): while True: x = input('ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΊΠ»Π΅ΡΠΎΠΊ Π² ΠΊΠ²Π°Π΄ΡΠ°ΡΠ΅ ') if x == 'stop': break elif not x.isdigit(): print ('Π²Ρ Π²Π²Π΅Π»ΠΈ Π½Π΅ ΡΠΈΡΠ»ΠΎ ' * 3 ) else: num = int(x) if num < 40: print ('ΡΠ»ΠΈΡΠΊΠΎΠΌ ΠΌΠ°Π»Π΅Π½ΠΊΠΎΠ΅ ΡΠΈΡΠ»ΠΎ') else: summaMassiv1 = int(num) * int(num) print ( summaMassiv1 ) print ( summaMassiv1 ) break # ΠΎΠ±ΡΡΠ²Π°Π΅Ρ Π΄Π΅ΠΉΡΡΠ²ΠΈΠ΅ ΡΠΈΠΊΠ»Π° True obj = MyClass() obj.recieve_val() # ΠΏΠ΅ΡΠ°ΡΠ°Π΅ΠΌ ΠΎΠ±ΡΠ΅ΠΊΡ print (obj.val)
|
1 answer
Well, already here
obj = MyClass()
will not work, because
def __init__(self, arg):
those. At least one argument is required. Further, when entering the number we get an error, because there will be a conversion to int, which does not have an isdigit () method - it is a string one and you need to do an inverse transformation (and catching the exception also does not hurt)
and about why it is impossible to output: you don't assign an attribute anywhere, there is no call to self.ipdate_val (x)
on the knee came something like this:
def recieve_val(self): while True: x = input('ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΊΠ»Π΅ΡΠΎΠΊ Π² ΠΊΠ²Π°Π΄ΡΠ°ΡΠ΅ ') str_x = str(x) self.ipdate_val(x) if x == 'stop': break elif not str_x.isdigit(): print ('Π²Ρ Π²Π²Π΅Π»ΠΈ Π½Π΅ ΡΠΈΡΠ»ΠΎ ' * 3 ) else: num = int(x) if num < 40: print ('ΡΠ»ΠΈΡΠΊΠΎΠΌ ΠΌΠ°Π»Π΅Π½ΠΊΠΎΠ΅ ΡΠΈΡΠ»ΠΎ') else: summaMassiv1 = int(num) * int(num) print ( summaMassiv1 ) print ( summaMassiv1 ) break # ΠΎΠ±ΡΡΠ²Π°Π΅Ρ Π΄Π΅ΠΉΡΡΠ²ΠΈΠ΅ ΡΠΈΠΊΠ»Π° True
|