Use a for loop to print a triangle like the one below. Allow the user to specify how high the
triangle should be.
*
**
***
****
height = int(input("Enter the height of the triangle: "))
for i in range(height):
print("*" * (i + 1))
This code will use the input()
function to get the height from the user, and then it will use a for
loop to iterate over the specified number of rows. On each iteration, it will print a number of asterisks equal to the current row number plus one.
To run this code, you can save it to a file with a .py
extension and run it using the python
command in a terminal or command prompt.
0 Comments