Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Experience with SharePoint and/or Microsoft Project desirable

Answered: 1 week ago

Question

Knowledge of process documentation (process flow charting)

Answered: 1 week ago