When I run the error appears: "Car() takes in Arguments". Can anyone help me? I don’t know what I did wrong

Asked

Viewed 33 times

-3

class Car():
    """Uma tentativa simples de representar um carro."""
    
    def _init_(self, make, model, year):
        """Inicializa os atributos que descrevem um carro."""
        self.make = make
        self.model = model
        self.year = year
        
    def get_descripte_name(self):
        """Devolve um nome descritivo, formatado de modo elegante."""
        long_name = str(self.year) + " " + self.make + " " + self.model
        return long_name.title()
        
my_new_year = Car("audi", "a4", 2016)
print(my_new_year.get_descripte_name())
  • briefly your init is only with an underscore on each side, it should be "_ init _ _" (no spaces), as this class would define the constructor with 3 inputs, because it does not exist it assumes the pattern, which is zero, so the error occurs because you try to pass 3

  • Thanks, now it’s working.

  • The name of the manufacturer must be __init__, with two _ at the beginning and two more at the end. There is a tb typing error in the variable my_new_year, that should be my_new_car: https://ideone.com/sEVz7K

1 answer

0


Flavia, I believe it is enough to adjust the signature of your init method to the one described below:

  def __init__(self, make, model, year):

The init method should always use two _ as prefix and suffix in your name. Very easy to 'pass', I have also lived this!

In addition, I believe you are using the incorrect variable name with the car instance in the cited example. Try the form below (and if possible adjust also the example):

my_new_car = Car("audi", "a4", 2016)
print(my_new_car.get_descripte_name()) 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.