logo CodeStepByStep logo

pad_string

Language/Type: Python parameters return string

Write a function named pad_string that accepts two parameters: a string and an integer representing a length. The function should pad the end of the string with spaces until its length is the given length. For example, the call of pad_string("hello", 8) should return "hello   " with 3 spaces after the word. If the string's length is already at least as long as the length parameter, your function should return the original string. For example, the call of pad_string("congratulations", 10) should return "congratulations" unmodified.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.