Question

Python Note- Do not use logical operators. Please keep it simple. The trustees of a small...

Python

Note- Do not use logical operators. Please keep it simple.

The trustees of a small college are considering voting a pay raise for their faculty members. They want to grant a 7 percent raise for those earning more than $50,000.00, a 4 percent raise for those earning more than $60,000.00 and 5.5 percent raise for all others. However, before doing so, they want to know how much this will cost. Write a program that will print the pay raise for each faculty member, the total amount of the raises, and the average of the raises. Also, print the total faculty payroll before and after the raise. Use the end of the file as a sentinel value.

The input data is as follows:

52500.00       64029.50      56000.00      50001.00
65500.00       42800.00      45000.50      68900.00
60000.00       59999.94      54120.25      64100.00
44000.50       80100.20      90000.00      41000.00
60500.50       72000.00      50000.01      50000.00
80001.75       60001.00

Here is the template given for this program:

def main():
  
inFile = open('program7.txt', 'r')
  
lineRead = inFile.readline()
while lineRead != '':
words = lineRead.split()
for word in words:
num = float(word)
print(format(num, '.2f'))
  
lineRead = inFile.readline()

# Close the file.
inFile.close()
  
# Call the main function.
main()

Homework Answers

Answer #1

Here i am providing the answer. Hope it helps. please give me a like. it helps me a lot.

Note:

  • "Screen shot of the code" for better understanding.
  • "Code to copy" for run the program in your IDE.
  • Please follow the code indentation properly to avoid indentation errors.

Code Image:

Input File Image:

Sample Output:

Code to Copy:

#Implementation of main method

def main():

   #Declare totalRaise and

   #assign as 0

   totalRaise = 0

   #Declare facultyCount and

   #assign as 0

   facultyCount = 0

   #Display statement

   print("pay raise for each faculty member ")

   #Display statement for Old salary and Raised Salary

   print("\n%-15s %-15s\n"%("Old Salary", "Raised Salary"))

   #open the file in read mode

   fileread = open("d:\\facultymembers\\pay.txt", "r")

   #read the lines of file

   filedata = fileread.readlines()

   # Iterate the file and

   for eachline in filedata:

       # Split the on space

       content = eachline.strip().split()

       #using the sentinel value

       #check the up to value is empty

       if content!='':

           # Iterating over each salary

           for eachSalary in content:

               #convert eachsalary into float

               eachSalary = float(eachSalary)

               # if the salary range is greater than 60000

               # calculate the raise salary

               if eachSalary > 60000:

                   raiseSalary = eachSalary * (4/100.0)

               # if the salary range is greater than 50000

               # calculate the raise salary

               elif eachSalary > 50000:

                   raiseSalary = eachSalary * (7/100.0)

               # if the salary range is less than 50000

               # calculate the raise salary

               # 5.5 percentage for all others

               else:

                   raiseSalary = eachSalary * (5.5/100.0)

               # calcaulating total raise salary

               totalRaise = totalRaise + raiseSalary

               #Display statement of pay raise for each faculty member

               # from the file

               print(" %-15.2f %-15.2f"%(eachSalary, eachSalary+raiseSalary))

               # Incrementing faculty count

               facultyCount = facultyCount + 1

   # Display statement for total amount of raises

   print("\n Total Amount of raises: " + str(totalRaise))

   # Display statement for average of the raises

   print(" Average of the raises: " + str(totalRaise/float(facultyCount)) + " \n")

      

#call main method

main()

Thank you. please like.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT