0

UserAnswers() missing 1 required positional argument: 'a5'

I'm new to python and am trying to learn the basics, I know how to use cpp, java, and a couple of other programing languages, but decided to start practicing with python and I'm running into this problem. I created two basic modules, one of them is being used as the main program, while the other is being used to store a class that will store user data; when I try to store information in the class it gives me the following error "UserAnswers() missing 1 required positional argument: 'a5' ", and I'm not what the problem is.

The following is the code from Main.py:

...
name = input("What's your name: ")
gender = input("What's your gender: ")
age = input("What's your age: ")

__users.append(PersonInformation.User(name, gender, age)) #enters the basic information of the user with the constructor

Questions.Question1()
a1 = input()
Questions.Question2()
a2 = input()
Questions.Question3()
a3 = input()
Questions.Question4()
a4 = input()
Questions.Question5()
a5 = input()

__users[len(__users)] = PersonInformation.User.UserAnswers(a1, a2, a3, a4, a5)
...

The following is from PersonInformation.py while taking information from the User class:

...
def UserAnswers(self, a1, a2, a3, a4, a5):
    self.personAnswers.insert(0, a1)
    self.personAnswers.insert(1, a2)
    self.personAnswers.insert(2, a3)
    self.personAnswers.insert(3, a4)
    self.personAnswers.insert(4, a5)
...

I know the code in both modules can be improved by a lot, but for learning purposes I just entered something simple and easy to read. As a final note I'm trying to store the information in a list inside the Main.py module.

Daniel Walker
  • 5,220
  • 3
  • 18
  • 39
  • Welcome to Stack Overflow. Please include the full traceback error. – ewong May 27 '22 at 03:16
  • In `PersonalInformation` you probably have a `class User` where `def UserAnswers` as listed is defined. You need to create an instance of `class User` by doing something like `user = PersonalInformation.User()` and then call `user.UserAnswers(a1, a2, a3, a4, a5)`. See the [linked thread](https://stackoverflow.com/questions/17534345/typeerror-missing-1-required-positional-argument-self) for additional info (note that the example has the `self` argument and no arguments were provided when OP tried to call the one directly on the class instead of the instance). – metatoaster May 27 '22 at 03:23
  • Thanks so much for your help, you don't know how much this helped me, I was struggling to find something so easy. I had another problem yesterday as well were I was trying to call a list but it was giving me an error, turns out I was calling the same def again by accident XD. But anyway, thanks, this really helped – Pixel Arcade May 27 '22 at 17:19
  • I don't know how to put your comment as an answer for this question, but yea, thanks. – Pixel Arcade May 27 '22 at 17:23

0 Answers0