Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python And the digits 0-7. Write the scripts octal To Decimal.py and decimal To

ID: 3802866 • Letter: P

Question

Python And the digits 0-7. Write the scripts octal To Decimal.py and decimal To Octal.py, which convert numbers between the octal and decimal representations of integers. These scripts use algorithms similar to those of the binary To Decimal and decimal To Binary scripts developed in Examples 4 and 5 in the lecture notes. the Payroll Department keeps a list of employee information for each pay period in a text file. the format of each line of the file is the following: name> wage> worked> Eg. Smith 45.00 12 Write a Python program that inputs a filename from the user and prints to the terminal a report of the wages paid to employees for the given period. the report should be in a tabular format with the appropriate header. Each line should contain an employee's name, the hours worked, and the wages paid for that

Explanation / Answer

def readFile():
    #open file
    file = open('emp.txt', 'r')
    store = {}
    #for each line of file
    for line in file:
        #split line in three parts
        part = line.split()
        name = part[0]
        wage = int(part[1])
        hour = int(part[2])
        #if name is already found in dictionary, add wages and hours
        if name in store:
            store[name][0] += wage
            store[name][1] += hour
        #else create new entry to dictionary
        else:
            temp = [wage, hour]
            store[name] = temp
    #print all details in tabular form
    print ("Name Wage Hour")
    for i, j in store.items():
        print (i, j[0], j[1])

readFile()


output:
Name Wage Hour
santt 35 12
rajkk 80 12
sakss 45 19

emp.txt
santt 35 12
rajkk 70 10
sakss 45 19
rajkk 10 2