7 kyu
"Center yourself", says the monk.
912 of 1,605siebenschlaefer
Description:
Your company MRE Tech has hired a spiritual consultant who advised on a new Balance policy: Don't take sides, don't favour, stay in the middle. This policy even applies to the software where all strings should now be centered. You are the poor soul to implement it.
Task
Implement a function center
that takes a string strng
, an integer width
,
and an optional character fill
(default: ' '
) and returns a new string of
length width
where strng
is centered and on the right and left padded with
fill
.
center(strng, width, fill=' ')
If the left and right padding cannot be of equal length make the padding on the left side one character longer.
If strng
is longer than width
return strng
unchanged.
Examples
center('a', 3) # returns " a "
center('abc', 10, '_') # returns "____abc___"
center('abcdefg', 2) # returns "abcdefg"
Strings
Fundamentals
Similar Kata:
Stats:
Created | Jul 16, 2017 |
Published | Jul 16, 2017 |
Warriors Trained | 3051 |
Total Skips | 82 |
Total Code Submissions | 7609 |
Total Times Completed | 1605 |
Python Completions | 912 |
C Completions | 122 |
JavaScript Completions | 613 |
COBOL Completions | 3 |
Total Stars | 53 |
% of votes with a positive feedback rating | 91% of 329 |
Total "Very Satisfied" Votes | 280 |
Total "Somewhat Satisfied" Votes | 41 |
Total "Not Satisfied" Votes | 8 |
Total Rank Assessments | 12 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |