2019-08-01 20:00:30

Guys, there is a class with this function inside...

def add_new_skills(self, name):
       self.skills.append(skill)

Ok so, if You've realized there is a possible variable inside paranteses. i mean the skill word without s, what it's for, can you explain to me? i mean why not an empthy string instead with appending line.

at first i thought it refers the "skill" variable on *for loop* below but, it doesn't sound reasonable to me.

Full code.

class worker:
    staff = []

    def __init__(self, name):
        self.name = name
        self.skills = []
        self.add_member()

    def new_member(self):
        self.staff.append(self.name)
        print("{} added to the staff.".format(self.name))

    def view_staff(self):
        print("Member list")
        for member in self.members:
            print(member)

    def add_new_skills(self, name):
       self.skills.append(skill)

    def view_skills(self):
        print({}'s skills: ".format(self.name))
        for skill in self.skills:
            print(skill)

2019-08-01 20:06:11

This will not compile/run. Change the skill item to name. Also, alter the name of the function -- it is misleading, because it only adds a signel skill, not multiple.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2019-08-03 10:35:18

Ethin wrote:

This will not compile/run. Change the skill item to name. Also, alter the name of the function -- it is misleading, because it only adds a signel skill, not multiple.



u mean will i put self.name instead of skill?

but skills placed inside self.skills isn't it?

2019-08-03 11:28:28

The purpose of that function i'm going to assume is to add a skill to a list of skills for that worker, but the given code is incorrect and won't work. When you pass a variable to a function, what its called internally is arbitrary. In that function add_new_skills(), the passed variable is called "name", except you try to add "skill" to self.skills, which doesn't exist and will cause an error. This means you either need to change the internal name of the function from "name" to "skill", or change what you append to self.skills, like so:

def add_new_skills(self, name):
   self.skills.append(name)

Or:

def add_new_skills(self, skill):
   self.skills.append(skill)
-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-08-03 20:29:53

@4 Magrib, with your version of code: def add_new_skills(self, skill):
   self.skills.append(skill)

instead of (skill) variable can't we pass an empty list?

i mean like this; self.skills.append([])

or an empty string like this, self.skills.append("")

2019-08-04 07:08:55

Yes, and that would add an empty list within a list, or an empty string into the list, but this would also make the function not do anything with the variable you pass to it. What ends up in self.skills, using that function, entirely depends on what you pass the function, if you put "add_new_skills("")" it would append that empty text string into self.skills, or if you put "add_new_skills([])" it would append the empty list into self.skills.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer