Question: Using Nested for-loops to Shrink Words (python) For this task youll use nested for-loops to print the same string a number of times, each time

Using Nested for-loops to Shrink Words (python)

For this task youll use nested for-loops to print the same string a number of times, each time decreasing the spacing between the characters in the string until there are no spaces the final time the string is printed. Youll also have to convert the string to a list to access each character. Use the list() function to do this. Youll need two functions for this program:

shrink(): Takes two arguments and returns nothing. The first argument is the string and the second argument is the number of lines of outputi.e., the number of times the string is printed. Uses nested for-loops to print the string. If nlines is the number of lines of output, the first line of output should have nlines - 1 spaces between each character. The second line of output should have nlines - 2 spaces between each character. This continues until the last line of output has nlines - nlines spaces between each character. The outer for-loop should produce the number of spaces, and the inner loop should loop through all the characters, printing each character and the spaces that follow it.

main(): Prompts user for the string to shrink and the number of lines as shown in the listings below. Calls shrink().

Enter string: Hello

Enter number of lines: 4

H e l l o

H e l l o

H e l l o

Hello

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!