Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The program then loops through each employee and reports if their earnings is within 5,000 of the average earnings
- # of all employees.
- # Sample interaction:
- # Please enter the employee name or * to finish: d
- # Please enter the salary in thousands for d: 50
- # Please enter the employee name or * to finish: e
- # Please enter the salary in thousands for e: 48
- # Please enter the employee name or * to finish: f
- # Please enter the salary in thousands for f: 52
- # Please enter the employee name or * to finish: g
- # Please enter the salary in thousands for g: 0.010
- # Please enter the employee name or * to finish: h
- # Please enter the salary in thousands for h: 100
- # Please enter the employee name or * to finish: *
- # d, 50000.00
- # e, 48000.00
- # f, 52000.00
- #
- # function to get a floating point number
- # if successful the floating point number will be returned
- # otherwise the user will have to continue attempting to enter the number
- # @param m is the prompt to the user.
- # @return a floating point number supplied by the user
- def getFloat(m):
- # infinate loop to acquire the score
- while True:
- num = input(m)
- try:
- # try to turn s into a float
- floatNum = float(num)
- # successful ~ leave the loop and return the score
- return floatNum
- except:
- # float cast failed ~ message user and try again
- print("I was expecting a number, please try again...")
- # program main ~ entry point of execution
- def main():
- # declare the data arrays
- employees = []
- salaries = []
- # flag as loop control variable
- done = False
- # get employee names and earnings until the sentinal is entered
- while not done:
- # get the employee's name
- name = input("Please enter the employee name or * to finish: ")
- # check for a '*' to see if we are done or not
- if name != '*':
- # no '*' so we keep going
- # set a prompt for getting the salary
- prompt = "Please enter the salary in thousands for " + name + ": "
- # use the getFloat method from last assignment to get the earnings for the employee
- # and convert it from "in thousands" to the true value
- earnings = (1000 * getFloat(prompt))
- # append the employee name to the employee array
- employees.append(name)
- # append the salary to the parallel salary array
- salaries.append(earnings)
- else:
- done = True
- # now that we have the employees, we can find the average using a loop and dividing by the array length
- # set the accumulator for the total
- total = 0
- # find the grand total
- for s in salaries:
- total += s
- # calculate the avarage salary
- averageSalary = total / len(salaries)
- # now that we have the average salary we can start looking at the employees and comparing them using a loop
- # set the minumum and maximum threshholds for testing
- minThreshold = averageSalary - 5000
- maxThreshold = averageSalary + 5000
- print("\nThe average salary is: $ %0.2f" % (averageSalary))
- print("\nEmployees earning between $ %0.2f and $ %0.2f are:" % (minThreshold, maxThreshold))
- # loop through all the employees and test them to see if they are in the salary range
- for i in range(len(salaries)):
- # if the salary for the employee is greater than the min and less than the max thresholds print employee info
- if (salaries[i] > minThreshold) and (salaries[i] < maxThreshold):
- print("%s, $ %0.2f" % (employees[i], salaries[i]))
- # execute the application
- main()
- def swap( A, x, y, E):
- tmp = A[x]
- tmp2 = E[x]
- A[x] = A[y]
- E[x] = E[y]
- A[y] = tmp
- E[y] = tmp2
- def bubblesort(A, E):
- for i in range (len(A)):
- for k in range(len(A) - 1):
- first = k
- second = k+1
- if(A[first] > A[second]):
- swap(A, first, second, E)
- print(A)
- temp = input("Hit Enter for the next step:\n")
- def main():
- # append the employee name to the employee array
- myArray = employees.append(name)
- #append the salary to the parallel salary array
- salaries.append(earnings)
- employees = []
- earnings = []
- # input the data
- # process
- bubblesort(earnings, employees)
- print(myArray)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement