← Back to challenges

Employee Parsing

PythonHardobjectsclasseslanguage_fundamentals

Instructions

In the class Employee, implement the instance attributes as firstname, lastname and salary.

Create the method from_string() which parses a string containing these attributes and assigns them to the correct properties. Properties will be separated by a dash.

Examples

emp1 = Employee("Mary", "Sue", 60000)
emp2 = Employee.from_string("John-Smith-55000")
emp1.firstname ➞ "Mary"

emp1.salary ➞ 60000

emp2.firstname ➞ "John"

emp2.salary ➞ 55000

Notes

  • The salary is an integer.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.