11/15/2020

Python Explanation (Edabit // Employee class with keywords)

 Hello!

Today I will solve this question!

Create a class Employee that will take a full name as argument, as well as a set of none, one or more keywords. Each instance should have a name and a lastname attributes plus one more attribute for each of the keywords, if any.

Examples

john = Employee("John Doe")
mary = Employee("Mary Major", salary=120000)
richard = Employee("Richard Roe", salary=110000, height=178)
giancarlo = Employee("Giancarlo Rossi", salary=115000, height=182, nationality="Italian")

john.name ➞ "John"
mary.lastname ➞ "Major"
richard.height ➞ 178
giancarlo.nationality ➞ "Italian"

And this is my solved code!

class Employee:
def __init__(self, name, salary=0, height=0, nationality="", subordinates=""):
self.firstname, self.lastname = name.split(' ')
self.salary = salary
self.height = height
self.nationality = nationality
self.subordinates = subordinates

First, the first name and the last name is the name splited.

Wendy (Split) Nickel

Next, we have the variable salary.

Put the salary into the self.salary.

Height, nationality, and subordinates is also same!

Put the (height, nationality subordinates) into the self.(height, nationality subordinates) .



That was really easy!

Bye!!!

0 件のコメント:

Super Leo 4!

  Leo : Let's do this! Reimu : I'll kill those monsters, so you go! Leo : Yeah! I'll go to the goal!  Leo : Let's go〜! ? Wai...