Question
in csis 152 style

Read the initial employee information from a text file and store the employee information into a list of sublists called empR

python programming language
0 0
Add a comment Improve this question Transcribed image text
Answer #0

thanks for the question, here is the compelte code in python,m ake sure you updat the filename inside the main() function that needs to be read

here is the code with screenshot

==================================================================================

import os
def readfile(filename):
    if os.path.isfile(filename) is not True: return None
   
records=[]
    with open(filename,'r') as infile:
        for line in infile.readlines():
            line = line.strip().split(',')
            if len(line)==4:
                records.append([int(line[0]),line[1].strip(),float(line[2]),int(line[3])])
        return records

def printRecords(records):
    print('{0:<10}{1:<15}{2:>10}{3:>10}{4:>15}'.format('ID','Name','PayRate','Hours','GrossPay'))
    print('='*(60))
    for rec in records:
        if rec[3]<=40:grosspay=rec[2]*rec[3]
        else: grosspay=40*rec[2]+ (rec[3]-40)*rec[2]*1.5
        print('{0:<10}{1:<15}{2:>10}{3:>10}{4:>15}'.format(rec[0],rec[1],'${0:.2f}'.format(rec[2]),rec[3],\
                        '${0:.2f}'.format(grosspay)))

def addRecord(records):
    print('Add Record (enter -999 for ID to quit)')
    while True:
        id = int(input('Enter employee ID: '))
        if id==-999:return
       
name=input('Enter employee name: ')
        payrate=float(input('Enter payrate for the employee: $'))
        hours=int(input('Enter hours worked: '))
        records.append([id,name,payrate,hours])

def deleteRecordByID(records):
    print('Enter ID of the employee you want to delete')
    id = int(input('Enter Employee ID you want to delete: '))
    for i in range(len(records)):
        if records[i][0]==id:
            records.pop(i)
            print('Record deleted from empRoster successfully!')
            return
   
print('No employee exist with this ID.')



def deleteRecordByLastName(records):
    print('Enter last name of the employee you want to delete')
    lastname = input('Enter Employee Last Name: ').lower()
    for i in range(len(records)):
        if records[i][1][-len(lastname):].lower()==lastname:
            records.remove(records[i])
            print('Record deleted from empRoster successfully!')
            break



def
printOvertimeWorkers(records):
    print('Employee who worked overtime(>40 hrs)')
    for rec in records:
        if rec[3]>40:
            print(rec[1])

def main():
    filename='D:\\emp.txt'
   
empRoster = readfile(filename)
    if empRoster==None:
        print('Not able to read data from file {}'.format(filename))
    else:
        printRecords(empRoster)
    addRecord(empRoster)
    printRecords(empRoster)
    deleteRecordByID(empRoster)
    printRecords(empRoster)
    deleteRecordByLastName(empRoster)
    printRecords(empRoster)
    printOvertimeWorkers(empRoster)
main()
==================================================================================

import os def readfile (filename): if os.path.isfile (filename is not True: return None records- ] with open (filename, ) as

def deleteRecordByID (records) print (Enter ID of the employee you want to delete) id - int (input (Enter Employee ID you w

def main filename-, D: \\emp . txt , empRoster readfile (filename) if empRoster--None: print (Not able to read data from fil

thanks !

Add a comment
Know the answer?
Add Answer to:
in csis 152 style python programming language Read the initial employee information from a text file...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT