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
****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:
public class Test2 { public static void indent(String str, int numSpaces){ for(int i = 0; i < numSpaces; ++i){ System.out.print(" "); } System.out.println(str); } public static int center(String str, int screenWidth){ int spacesLeft = screenWidth - str.length(); indent(str, spacesLeft / 2); return spacesLeft; } public static void main(String[] args){ indent("Hello", 10); center("Center me", 50); } } THANK YOU!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
