Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function printDiamond ( n ) which prints ascii art of a diamond with a size based on the positive integer n . For
Write a function printDiamond which prints ascii art of a diamond with a size based on the positive integer For example, printDiamond would print:
Whereas printDiamond would print:
You'll want to create a loop where each iteration prints a single line of the ascii art. To draw multiple spaces and multiple asterisks on a single line, consider using the operator, which can be used to repeat a string an integer number of times.
Hint : Every line is composed of three parts: outer spaces, inner asterisks, and two numbers on the outside of the diamond. For example, the second line of the size diamond has one space, then the number then two asterisks, then the number again. Consider each of these parts individually, note how they change between iterations, then determine how to map the loop control variable to each part separately.
Hint : if you're feeling overwhelmed, simplify the problem by breaking it down into parts! Start by just making the top half of the diamond. First, get the numbers to appear correctly; second, add in the asterisks. Finally, add the leading spaces.
Hint : how can the program switch from the increasing top half to the decreasing bottom half? Consider using two separate loops one going up one going down or a sinale loop with a conditional that chanqes how the loop control variable is used.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started