← Back to challenges

Format V: Alignment

PythonHardstringsformattinglanguage_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 be formatted in order to get a certain outcome.

Write three template strings according to the following example. All final strings must have a length of 30 characters. Notice the period . at the end of the strings:

Example

name = "John"

left_align = "yourtemplatestringhere"
center_align = "yourtemplatestringhere"
right_align = "yourtemplatestringhere"

left_align.format(name) ➞ "My name is John              ."
center_align.format(name) ➞ "My name is        John       ."
right_align.format(name) ➞ "My name is               John."

Tips

The placeholders {:<x}, {:^x}, {:>x} are used to align left, center and right respectively within a width x.

For example:

"Credits: {:>7}".format(128) ➞ "Credits:     128"

Notes

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Orthogonal Vector