P
P
PeteDoherty2020-08-20 00:01:43
Python
PeteDoherty, 2020-08-20 00:01:43

What is the reason for the error in calling a class function?

Hello everyone, the question arose why, during the execution of the code, when calling a function, the interpreter gives an error 'int' object is not callable. Explain what is wrong and how to fix it

class Automobile: 
  def __init__(self, num, color, type_auto, health): 
    self.num = num 
    self.color = color 
    self.type_auto = type_auto 
    self.health = health
    
  def information(self): 
    print (self.num, self.color, self.type_auto, self.health) 
  
  def health(self, unhealth):
    self.health -= unhealth 
   
    
def Auto(): 
  num = int( input('Номeр автомобиля: ' )) 
  color = input('Цвет автомобиля: ' ) 
  type_auto = input('Тип автомобиля: ') 
  health = int(input('Состояние автомобиля (%): ')) 
  auto = Automobile(num, color, type_auto, health)
  unhealth = int(input())
  auto.health(unhealth)
  print(auto)

Auto()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Makhov, 2020-08-20
@PeteDoherty

You have healthdeclared it twice as a field and as a method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question