Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will ask the user to input an odd number in the range from

ID: 3674314 • Letter: W

Question

Write a program that will ask the user to input an odd number in the range from 1 – 25. The program will then display a diamond containing that many rows of stars. (The sample at the left would be the output for 9 rows.)

Hint: First, figure out the solution for the sample pattern (fixed value of 9 rows). Then, modify your program so that your user can input the number of rows in the diamond.

Explanation / Answer

def lineout (sp, st): s = "" for i in range (sp): s = "%s "%(s) for i in range (st): s = "%s*"%(s) print s n = 21 numspaces = (n-1) / 2 numstars = 1 while numspaces > 0: lineout (numspaces, numstars) numspaces -= 1 numstars += 2 while numstars > 0: lineout (numspaces, numstars) numspaces += 1 numstars -= 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote