Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python formatting code

Practice format specifications for width, alignment, numeric precision, and dynamic formatting.

Intermediate ~6 min read

Challenge 1

Format the price with exactly two digits after the decimal point.

python Your answer
price = 12.5
result = 
print(result)

Press Ctrl⌘Enter to check your answer

Challenge 2

Center the text inside a field eight characters wide.

python Your answer
name = "Ada"
result = f""
print(result)

Press Ctrl⌘Enter to check your answer

Challenge 3

Format the amount with thousands separators and two decimal places.

python Your answer
amount = 12345.6789
result = f""
print(result)

Press Ctrl⌘Enter to check your answer

Challenge 4

Use the width and precision variables to format the value dynamically.

python Your answer
value = 12.3456
width = 9
precision = 2
result = f""
print(result)

Press Ctrl⌘Enter to check your answer