← Back to challenges

Format VI: Padding

PythonHardformattingstringslanguage_fundamentals

Instructions

For each challenge of this series you do not need to submit a function. Instead, you need to submit a template string that can formatted in order to get a certain outcome.

Write a three templates string according to the following example. All final strings must have a length of 20 characters:

Example

starry = "yourtemplatestringhere"
dash = "yourtemplatestringhere"
money = "yourtemplatestringhere"

starry.format("Starry") ➞ "*******Starry*******"
dash.format("Dash") ➞ "----------------Dash"
money.format("Money") ➞ "Money$$$$$$$$$$$$$$$"

Tips

You can pad a string with a placeholder in the format {:cdx} where c is the padding character, d is one of three directions (<, ^ or >) and x is the width.

For example:

"Best score{:->15}".format('AAA') ➞ "Best score------------AAA"

Notes

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Changing Mixed Types