107k views
0 votes
Write a loop that outputs the numbers in a list named salaries. The outputs should be formatted in a column that is right-justified, with a field width of 12 and a precision of 2.

User Rck
by
3.2k points

2 Answers

1 vote

Final answer:

To output the numbers in a list named salaries in a right-justified column with a field width of 12 and a precision of 2, you can use the provided loop.

Step-by-step explanation:

To output the numbers in a list named salaries in a right-justified column with a field width of 12 and a precision of 2, you can use the following loop:

for salary in salaries:
print('{:>12.2f}'.format(salary))

This loop iterates over each salary in the list and uses the '{:>12.2f}' format specifier to display each number in a column that is right-justified, with a field width of 12 and a precision of 2. This format specifier ensures that each number is displayed with two decimal places.

User Kifsif
by
3.8k points
1 vote

Answer:

Following is the loop statement in the Python programming language

salaries=[93.85967,4232.32,13343.3434] #storing the values in salaries

for k in salaries:#iterating the loop

print("%12f"%round(k,2))# print the width of 12 and a precision of 2

Output:

93.860000

4232.320000

13343.340000

Step-by-step explanation:

Following is the description of the statement

  • Declared a dictionary "salaries" and initialized some values into it.
  • iterating the for a loop .
  • In this for loop print the width 12 and a precision of 2 .The print statement in python will
  • print the data with width 12 and a precision of 2 in the console window

User Dylan Bijnagte
by
3.4k points