Question

In: Computer Science

Write a Python program The Hay System is a job performance evaluation method that is widely...

Write a Python program

The Hay System is a job performance evaluation method that is widely used by organizations around the world. Corporations use the system to map out their job roles in the context of the organizational structure. One of the key benefits of the method is that it allows for setting competitive, value-based pay policies. The main idea is that for each job evaluation, a number of factors (such as Skill, Effort, Responsibility and Working Conditions) are evaluated and scored by using a point system. Then, the cumulative total of points obtained will be correlated with the salary associated with the job position. As an engineering student, you have been commissioned to implement a simplified version of the Hay method. Particularly, the hiring company (which is called David and Joseph Ltd) is interested in getting the salary (or hay system score) for several job descriptions currently performed in the company. Data Representation Unfortunately, the company David and Joseph Ltd. has very strict security policies. Then, you will not be granted access to the main data base ). Instead, all the information needed has been compiled in files with the following characteristics. File 1 The first line of the file contains 1 positive integer: num words≤ 10000, the number of words in the Hay Point dictionary. num words lines follow; each contains a word (a string of up to 16 lower-case letters) and a dollar value (an integer between 0 and 1000000).

You can safely assume that the num words words in the dictionary are distinct. Each description word-value is terminated by a line containing a period. You can take a look about how File 1 looks below.

7
administer 100000
.
spending 200000
.
manage 50000
.
responsibility 25000
.
expertise 100
.
skill 50
.
money 75000
.

Please note that for this file, num words is equal to 7. File 2 The first lines of the file contains a varyingly number of comments that must be ignored. You can recognize a comment line because it always start with the # character. Following the comments there is one job description. A job description consists of between 1 and 200 lines of text; for your convenience the text has been converted to lower case and has no characters other than letters, numbers, and spaces. Each line is at most 200 characters long. You can take a look about how File 2.1 looks below.

#Hello how are you

# This comment does not make sense

# It is just to make it harder

# The job description starts after this comment, notice that it has 4 lines.

# This job description has 700150 hay system points \\

the incumbent will administer the spending of kindergarden milk money and exercise responsibility for making change he or she will share responsibility for the task of managing the money with the assistant whose skill and expertise shall ensure the successful spending exercise

Below, you can find a second example of how File 2.2 could look like.

#This example has only one comment

this individual must have the skill to perform a heart transplant

and expertise in rocket science

The Hay System When applying the Hay System to the latest File 2 example (i.e., this individual must have the skill to perform a heart transplant and expertise in rocket science ) on the Hay Point dictionary coded in File 1, the job description gets a total of 150 points (or salary in dollars). This score is obtained because exactly two words (i.e., expertise and skill) of the job description are found in the dictionary. Particularly, expertise and skill have a score of 100 and 50 dollars, respectivelly.

Question 1: create dictionary

Complete the create dictionary function, which reads the information coded in the File 1 and returns a hay points dictionary. See below for an explanation of exactly what is expected. from typing import Dict, TextIO def create_dictionary(file1: TextIO) -> Dict[str, int]: ’’’Return a dictionary populated with the information coded in file1. >>> File_1 = open(’File1.txt’) >>> hay_dict = create_dictionary(File_1) >>> hay_dict {’administer’: 100000, ’spending’: 200000, ’manage’: 50000, ’responsibility’: 25000, ’expertise’: 100, ’skill’: 50, ’money’: 75000} """ Please note that the variable file1 is of type TextIO, then you can assume that file was already open and it is ready to be read.

Question 2: job description (24 points) Complete the job description function, which reads the information coded in the File 2 to return a list of strings with the job description. See below for an explanation of exactly what is expected. def job_description(file2: TextIO) -> List[str]: ’’’Return a string with the job description information coded in file2. >>> File_2 = open(’File2_1.txt’) >>> job_desc = job_description(File_2) >>> job_desc [’the’, ’incumbent’, ’will’, ’administer’, ’the’, ’spending’, ’of’, ’kindergarden’, ’milk’, ’money’, ’and’, ’exercise’, ’responsibility’, ’for’, ’making’, ’change’, ’he’, ’or’, ’she’, ’will’, ’share’, ’responsibility’, ’for’, ’the’, ’task’, ’of’, ’managing’, ’the’, ’money’, ’with’, ’the’, ’assistant’, ’whose’, ’skill’, ’and’, ’expertise’, ’shall’, ’ensure’, ’the’, ’successful’, ’spending’, ’exercise’] ’’’ Please note that the variable file2 is of type TextIO, then you can assume that file was already open and it is ready to be read.

Question 3: hay points (24 points) Complete the hay points function, which for a job description, output the corresponding salary computed as the sum of the Hay Point values for all words that appear in the description. Words that do not appear in the dictionary have a value of 0. See below for an explanation of exactly what is expected. def hay_points(hay_dictionary: Dict[str, int], job_description: List[str]) -> int: ’’’Returns the salary computed as the sum of the Hay Point values for all words that appear in job_description based on the points coded in hay_dictionary >>> File_1 = open(’File1.txt’) >>> File_2 = open(’File2_1.txt’) >>> hay_dict = create_dictionary(File_1) >>> job_desc = job_description(File_2) >>> points = hay_points(hay_dict, job_desc) >>> print(points) >>> 700150 ’’’

Question 4: my test (0 points) The function my test is there to give you a starting point to test your functions. Please note that this function will not be graded, and it is there only to make sure that you understand what every function is expected to do and to test your own code. Note: In order for you to test your functions one at a time, comment out the portions of the my test() function that call functions you have not yet written. The expected output for the function calls is as follows:

The dictionary read from File1.txt is: {’administer’: 100000, ’spending’: 200000, ’manage’: 50000, ’responsibility’: 25000, ’expertise’: 100, ’skill’: 50, ’money’: 75000}

The string read from File2_1.txt is: [’the’, ’incumbent’, ’will’, ’administer’, ’the’, ’spending’, ’of’, ’kindergarden’, ’milk’, ’money’, ’and’, ’exercise’, ’responsibility’, ’for’, ’making’, ’change’, ’he’, ’or’, ’she’, ’will’, ’share’, ’responsibility’, ’for’, ’the’, ’task’, ’of’, ’managing’, ’the’, ’money’, ’with’, ’the’, ’assistant’, ’whose’, ’skill’, ’and’, ’expertise’, ’shall’, ’ensure’, ’the’, ’successful’, ’spending’, ’exercise’]

The salary computed is 700150

Solutions

Expert Solution

Ok i will complete this assigmnemt completely.

So , first I had created the two files as follows:

data = '''7
administer 100000
.
spending 200000
.
manage 50000
.
responsibility 25000
.
expertise 100
.
skill 50
.
money 75000
.'''
f = open('File1.txt',"w")
f.write(data)
f.close()

data = '''#Hello how are you
# This comment does not make sense
# It is just to make it harder
# The job description starts after this comment, notice that it has 4 lines.
# This job description has 700150 hay system points \\
the incumbent will administer the spending of kindergarden milk money and exercise responsibility for making change he or she will share responsibility for the task of managing the money with the assistant whose skill and expertise shall ensure the successful spending exercise
Below, you can find a second example of how File 2.2 could look like.'''
f = open("File2_1.txt","w")
f.write(data)
f.close()

Question 1:


################################
# QUESTION 1
################################
File_1 = open("File1.txt")
def create_dictionary(File_1):
  data = File_1.read().split("\n")
  hay_dict = {}
  n = int(data[0])
  data = data[1:] # remove the first elemtent
  for i in data:
    if i == ".": # remove the dots line
      data.remove(i)
  for i in range(n): # convert to dictionary
    i = data[i].split()
    hay_dict[i[0]] = int(i[1] )

  return hay_dict
hay_dict = create_dictionary(File_1)
File_1.close() # close the file
print(hay_dict)

Screenshot of output and code:

Question 2 :

################################
# QUESTION 2
################################

def job_description(file2):
  data = file2.read().split("\n")
  newData = []
  # # remove comments
  for i in data:
    i = i.strip()
    if i[0] != '#': # REMOVING THE COMMENTS
      newData.append(i)
  data = []
  for i in range(len(newData)):
    data.extend(newData[i].split())
  return data

File_2 = open('File2_1.txt') 
job_desc = job_description(File_2) 
print(job_desc)   

Screenshot of output and code:

Question 3 :


################################
# QUESTION 3
################################

def hay_points(hay_dictionary, job_description) -> int:
  total = 0
  for i in job_description:
    if i in hay_dictionary:
      total += hay_dictionary[i]
  return total
File_1 = open("File1.txt")
File_2 = open("File2_1.txt")
hay_dict = create_dictionary(File_1)
job_desc = job_description(File_2)
points = hay_points(hay_dict, job_desc)
print(points) 

Screenshot of output and code:

Question 4:)

################################
# QUESTION 4
################################
def my_test(file1, file2):
  File_1 = open(file1)
  hay_dict = create_dictionary(File_1)
  File_1.close()
  print(f"The dictionary read from {file1} is : {hay_dict}")
  File_2 = open(file2)
  job_desc = job_description(File_2)
  File_2.close()
  print(f"The string read from {file2} is: {job_desc}")
  points = hay_points(hay_dict, job_desc)
  print(f"The salary computed is {points}")


my_test("File1.txt", "File2_1.txt")  

Screenshot of output and code:

The complete code :


################################
# QUESTION 1
################################
File_1 = open("File1.txt")
def create_dictionary(File_1):
  data = File_1.read().split("\n")
  hay_dict = {}
  n = int(data[0])
  data = data[1:] # remove the first elemtent
  for i in data:
    if i == ".": # remove the dots line
      data.remove(i)
  for i in range(n): # convert to dictionary
    i = data[i].split()
    hay_dict[i[0]] = int(i[1] )

  return hay_dict
hay_dict = create_dictionary(File_1)
File_1.close() # close the file
print(hay_dict)

################################
# QUESTION 2
################################

def job_description(file2):
  data = file2.read().split("\n")
  newData = []
  # # remove comments
  for i in data:
    i = i.strip()
    if i[0] != '#': # REMOVING THE COMMENTS
      newData.append(i)
  data = []
  for i in range(len(newData)):
    data.extend(newData[i].split())
  return data

File_2 = open('File2_1.txt') 
job_desc = job_description(File_2) 
print(job_desc)   


################################
# QUESTION 3
################################

def hay_points(hay_dictionary, job_description) -> int:
  total = 0
  for i in job_description:
    if i in hay_dictionary:
      total += hay_dictionary[i]
  return total
File_1 = open("File1.txt")
File_2 = open("File2_1.txt")
hay_dict = create_dictionary(File_1)
job_desc = job_description(File_2)
points = hay_points(hay_dict, job_desc)
print(points) 

################################
# QUESTION 4
################################
def my_test(file1, file2):
  File_1 = open(file1)
  hay_dict = create_dictionary(File_1)
  File_1.close()
  print(f"The dictionary read from {file1} is : {hay_dict}")
  File_2 = open(file2)
  job_desc = job_description(File_2)
  File_2.close()
  print(f"The string read from {file2} is: {job_desc}")
  points = hay_points(hay_dict, job_desc)
  print(f"The salary computed is {points}")


my_test("File1.txt", "File2_1.txt")  

post a comment below , if any more help is required.

--------------------------------------------------

Hope you like the answer. Please upvote. Thank you.

--------------------------------------------------


Related Solutions

Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
Write a short evaluation of performance appraisal
Write a short evaluation of performance appraisal
a) Based on the binary tree implementation from the Python program below  write a recursive method that...
a) Based on the binary tree implementation from the Python program below  write a recursive method that calculates the number of leaf nodes in the tree. class Binaertre: def __init__(self, datatobjekt): self.data = datatobjekt self.forelder = None self.venstre_barn = None self.hoyre_barn = None @property def venstre_barn(self): return self.__venstre_barn @venstre_barn.setter def venstre_barn(self, node): self.__venstre_barn = node if node is not None: node.forelder = self @property def hoyre_barn(self): return self.__hoyre_barn @hoyre_barn.setter def hoyre_barn(self, node): self.__hoyre_barn = node if node is not None: node.forelder...
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
Calculating Delivery Cost Program in Python write a program in Python that will ask a user...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user to enter the purchase total, the number of the items that need to be delivered and delivery day. Then the system displays the cost of delivery along with the total cost. Purchase total > $150 Yes Number of the items (N) N<=5 N>=6 Delivery day Same Day Next Day Same Day Next Day Delivery charges ($) 8 N * 1.50 N * 2.50 N...
Address the four steps of the Deloitte performance evaluation system.
Address the four steps of the Deloitte performance evaluation system.
Job designs influence motivation and performance. What role might job designs have in the evaluation and...
Job designs influence motivation and performance. What role might job designs have in the evaluation and rewards of employees in the workplace?
Chapter 7 – Job Description, Performance Appraisal, Job Evaluation, and Job Design Exercises 1. Go online...
Chapter 7 – Job Description, Performance Appraisal, Job Evaluation, and Job Design Exercises 1. Go online and search for job descriptions. You will find this to be a popular topic. Find a specific job description (e.g., HR generalist). Describe what you found. Form groups. Each group should pick a job with which all group members have some familiarity (dentist, pizza delivery, fast food cashier, bank teller, etc.). Choose one or more of the exercises for the groups, and have them...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT