Question
MUST BE IN PYTHON 3: .format method format is a method of string and returns another string. Use {} in the string for the places
MUST BE IN PYTHON 3:
.format method
format is a method of string and returns another string. Use {} in the string for the places where a value will be positioned. inside the {} there are formatting options.
"{:[align][width][.precision][type]}".format( value )
Alignment is a character that tells how to align the output. < is left justified, > is right and ^ is centered. Width is the minimum size of the field precision, is how many digits to show after the decimal point ( if it's a float ) type is a character that describes what type of data it is formatting. s - string, d - decimal, f-float, % - Percentage ( and more )
There are many more options. Consult the documentation above for more information.
For instance,
print("{:<5}-{:>10.2f}".format("hi", 22.5828101838))
Will format the HI to be left justfied with a minimum of 5 spaces, followed by a dash with the floating point number 22.58.... right justified with 2 digits after the decimal. ( Try it and experiment with the results )
1) Get the title, a start integer and an end integer. Then output the title centered in 50 in a field 50 spaces large. (1 Point )
Enter title: Lab Results Enter start integer: 1 Enter end integer: 5 Lab Results
2) Output a line of = 50 characters wide. Then loop from the start number to the end number. For each value output the number left justified by 25, and the math.sqrt value of the number right justified by 25 with 2 decimal places. ( 1 Point )
My Lab ================================================== 1 1.00 2 1.41 3 1.73 4 2.00 5 2.24
3) Output the results table again, except the title should be right justified by 30, the value on the left left justified by 15, and the math.sqrt value right justified by 15 with 5 decimal points of precision, with a leading 0 fill character.
My Lab ============================== 1 000000001.00000 2 000000001.41421 3 000000001.73205 4 000000002.00000 5 000000002.23607
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started