In: Computer Science
* Write a program texttriangle.py. in python
This, too, is not a graphics program. Prompt the user for a small positive integer value, that I’ll call n. Then use a for-loop with a range function call to make a triangular arrangement of ‘#’characters, with n ‘#’ characters in the last line. Hint: [5]
Then leave a blank line. Then make a similar triangle, except start with the line with n ‘#’ characters. To make the second triangle, you can use a for-loop of the form discussed so far, but that is trickier than looking ahead to The Most General range Function and using a for-loop where a range function call has a negative step size.
# Function to demonstrate triangle
def texttriangle(n):
# outer loop to handle number of rows
# n in this case
for i in range(0, n):
# inner loop to handle number of
columns
# values changing acc. to outer
loop
for j in range(0, i+1):
# printing
stars
print("#
",end="")
# ending line after each row
print("\r")
##Leave a blank line
print("\r");
# outer loop to handle number of rows
# n in this case
for i in range(n, 0, -1):
# inner loop to handle number of
columns
# values changing acc. to outer
loop
for j in range(0 , i ):
# printing
stars
print("#
",end="")
# ending line after each row
print("\r")
# Driver Code
n = int(input("Enter positive integer value \n"));
texttriangle(n)
Output: