-2
class Profile:
    def __init__(self, fname, lname, phone, email):
        self.fname = fname
        self.lname = lname
        self.phone = phone
        self.email = email

profile1 = Profile('John','Doe','555-555-5555','test@gmail.com')

Is it possible to alter the code above to create more profiles without having to code them in one by one? I would like to attach the script to a button so that every time it is clicked it gives the user the ability to create a new unique profile.

iminertia
  • 39
  • 5
  • 1
    `newprofile = profile1 = Profile(firstname, lastname, phone, email)` where the variables are populated by the user. What is your actual question? – tripleee Jun 01 '22 at 04:00
  • How are the variable populated by the user? Sorry I'm new to python. Could I just add that line in somewhere? – iminertia Jun 01 '22 at 04:09
  • 1
    We don't know how you want that to happen. Trivially `firstname = input("Type your first name: ")` etc. – tripleee Jun 01 '22 at 04:13
  • Welcome to Stack Overflow. Please read [ask] and keep in mind that this is *not a discussion forum*. We can't help you *design* an overall program. Please think more carefully about exactly how you want things to work; make a list of requirements; try to work through it step by step; and then consider asking *separate* questions for whatever you get stuck on, *after* making your best effort to [figure them out](https://meta.stackoverflow.com/questions/261592). You should make sure you have a solid grasp of Python fundamentals before trying to design something like this. – Karl Knechtel Jun 01 '22 at 04:18
  • Possible duplicate of https://stackoverflow.com/questions/70797/how-to-prompt-for-user-input-and-read-command-line-arguments – tripleee Jun 01 '22 at 04:18
  • Thank you for taking the time to respond to such beginner questions. I understand how to get user input, but lets say I wanted 100 profiles would I need to code the profiles in 1 by 1? For example: ```newprofile = profile1 = Profile(firstname, lastname, phone, email)``` ```newprofile = profile2 = Profile(firstname, lastname, phone, email)``` and so on... @tripleee – iminertia Jun 01 '22 at 04:41
  • 1
    That's not valid syntax. Probably create a list and `append` each new profile to it in a loop. (Oh sorry, I see now that you copied a syntax error from my comment. It should be just `newprofile = Profile(...)`) – tripleee Jun 01 '22 at 04:43

0 Answers0