Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a Python program that uses nested for loop(s) to write a series of asterisks in the shell window in the shape of a square.

Develop a Python program that uses nested for loop(s) to write a series of asterisks in the shell window in the shape of a square. An additional requirement is to replace the center asterisk with an O. Part 1: 1. Use input and int functions to get a count value, from the user that is running the program. 2. Create a for loop that uses the range() function. The loop should iterate the number of times that the user entered. 3. Inside the loop, add a statement to print one asterisk and not break to the next line ( end='' ). 4. Run the program. You should see a single line of asterisks. The number of asterisks should equal the number entered by the user. 5. From here on down, the loop in Part 1 will be referenced as the Inner?Loop. Part 2: 6. Build a second for loop to execute the loop (Inner?Loop), that you completed in Part 1, multiple times. This new loop is the Outer?Loop. This loop should use the range() function to iterate through rows of asterisks. The number rows should equal the count entered by the user. 7. At this point, when a 5 is entered, the output should look like: ***** ***** ***** ***** ***** Part 3: 8. To get the O in the center The best solutions, that I have thought of, will replace the statement, in Part 2, that prints the asterisk. It will replace that one statement with an if/else structure to print an O in the center, or print an asterisk otherwise. 9. The center can be determined by the row being equal to the midpoint and the column being equal to the midpoint. The midpoint can be calculated as: mid = count // 2 10. Because the one asterisk should be in the middle, using odd numbers for the number of asterisks across, and the number of asterisks down, works better. 11. The final output, when a 5 is entered, should look like: ***** ***** **O** ***** *****

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

=+How can I use it in a new way?

Answered: 1 week ago