In: Computer Science
Write a function called 'make_triangle(char,n)' that uses a nested loop to return a string that forms a triangle. The return string should contain: one instance of char on the first line, two instances of char on the second line, and so on up to n instances of char on line n. Then n-1 instances of char on line n+1, and so on until the triangle is complete. Sample runs of the function looks as follows (this function called from IDLE, please note the end of line character at the end of the return string):
>>> make_triangle("+",6)
'+\n++\n+++\n++++\n+++++\n++++++\n+++++\n++++\n+++\n++\n+\n'
>>> make_triangle('*',3)
'*\n**\n***\n**\n*\n'
From IDLE, we could as print out the actual triangle as follows:
>>> print(make_triangle("+",6))
+
++
+++
++++
+++++
++++++
+++++
++++
+++
++
+
>>> print(make_triangle('*',3))
*
**
***
**
*
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! =========================================================================== def make_triangle(symbol, n): triangle = '' for i in range(1, n): triangle += symbol * i + "\n" for i in range(n, 0, -1): triangle += symbol * i + "\n" return triangle print(make_triangle("+",6)) print(make_triangle("*",3))
=============================================================