Question: Please write the function in python and also please include explantations for each line of code in the function and a screenshot to see the

Please write the function in python and also please include explantations for each line of code in the function and a screenshot to see the correct indentation.

Define a class named Worker which stores information about an worker's surname, first_name, id and weekly salary. The class must have the following:

  1. Create a worker from surname, first_name, worker_id and weekly_salary (float). For example: worker1 = Worker('Smith', 'John', 'SJ001', 522.70) Note: The data fields (surname, first_name, worker_id, weekly_salary) must all be defined as private instance variables.
  2. Create a worker from just the names and worker_id, but without the weekly_salary. For example: worker2 = Worker('Smith', 'Roger', 'SR002') Note: The default value for the weekly salary is 0.0.
  3. Return a string representing information about the worker. For example: the statement: print(worker1) would produce the output: John Smith (ID SJ001), weekly salary = $522.70
  4. The class should also provide functionality to get the names, the worker id and the weekly salary. For example, the code: print(worker1.get_names(), worker1.get_worker_id(), worker1.get_weekly_salary()) would produce the output: John Smith SJ001 522.70
  5. Finally, the class should provide functionality to set the weekly salary. For example: worker2.set_weekly_salary(522.70) Note: The weekly salary data field should only be changed if the corresponding parameter is larger than 0.0.
Test Result
worker1 = Worker('Smith', 'John', 'SJ001', 522.70) print(worker1) print(worker1.get_names(), worker1.get_worker_id(), worker1.get_weekly_salary())
John Smith (ID WS001), weekly salary = $522.70 John Smith WS001 522.70
worker2 = Worker('Smith', 'Roger', 'SR002') print(worker2) worker2.set_weekly_salary(-10.2) print(worker2) worker2.set_weekly_salary(333) print(worker2)
Roger Smith (ID SR002), weekly salary = $0.00 Roger Smith (ID SR002), weekly salary = $0.00 Roger Smith (ID SR002), weekly salary = $333.00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!