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 1

    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