****coding in PYTHON for a vry beginner**** (This question was answered but in a
ID: 3785525 • Letter: #
Question
****coding in PYTHON for a vry beginner**** (This question was answered but in a more advanced manner)
Assignment:
You will write a script with the following 2 functions that display text strings.
a. (5 pts)A function called indent that indents a string by a certain number of spaces. The function: - accepts 2 input arguments: a string and the number of spaces. - returns nothing (no output) - prints the string after printing the specified number of spaces. Make sure to have a docstring to describe the function.
b. (10 pts) A function called center that centers a string with respect to the screen width. The function: - accepts 2 input arguments: a text string and a screen width - prints the text string in the center of the screen - returns the number of indentation spaces The screen width is how many characters can fit across the screen. You can assume that the string length will be less than the screen width. Hint: call the indent function to indent by the appropriate number of spaces.
***THIS IS FOR A BEGINNER. Need a very basic coding in PYTHON. Nothing fancy like this:
THANK YOU!
Explanation / Answer
Ans.1.
def indent(string, numberOfSpaces):
for i in range(numberOfSpaces):
print " ",
print string
indent("abc", 5)
Ans.2
def indent(string, numberOfSpaces):
for i in range(numberOfSpaces):
print " ",
print string
def center(string, width):
l = len(string)
numberOfSpaces = (width - l)/2
indent(string, numberOfSpaces)
center("abc", 20)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.