Use a for loop to print an upside down 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, 0, -1):
print("*" * i)
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 a range of numbers from the height down to 1. On each iteration, it will print a number of asterisks equal to the current number in the range.
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