77.4k views
0 votes
Formatting. Given input that represents a floating point number, that is, made up of digits and at least one decimal point, convert the input to a float and print it with the following specifications: * field width of 12 * 2 decimal digits of precision * right justified For example, if the input is 1234.56789 The output will be 1234.57 Note the five spaces to the left of the digit 1.

Use the input statement in the skeleton: s = input("Input a float: ")

1 Answer

2 votes

Answer:

s = input("Input a float: ")

print("{:12.2f}".format(float(s)))

Step-by-step explanation:

  • Read a number from user using the input function of Python.
  • Use the format function of Python to correctly format the output according to the given requirements.
  • Note: Use Python 3.6 or above for this code to run without any issue.

Output:

Input a float: 1234.56789

1234.57

User Kolypto
by
5.2k points