Question: Python coding I need this code to format the output for this code to have :.2f in it somewhere the numbers need to output the

Python coding

I need this code to format the output for this code to have :.2f in it somewhere the numbers need to output the numbers in the format of 000.00 but I have no idea how to do that in my code.

my code:

fname = input('Enter the file name: ')

# print the header information

print('%-20s%-20s%-20s'%('Name', 'Hours', 'Total Pay'))

# open file to read

with open(fname, 'r') as f:

# read each line of the file in loop

for line in f:

# split the line into list of words

words = line.split()

# extract name

name = words[0]

# extract hours and convert to int

hours = int(words[1])

# extract wage and convert to int

wage = float(words[2])

# total pay will be hourly wage times no. of hours worked.

total_pay = hours*wage

# print the output lines

print('%-20s%-20s%-20s'%(name, hours, total_pay))

print (' ')

to make this code run you need a data.txt file with this in it.

Lambert 34 10.50 Osborne 22 6.25 Giacometti 5 100.70

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!