Exercise
Triangular Shape
Objective
Develop a Python program that prompts the user for a symbol and a width, and displays a triangle of that width using that symbol for the inner part, as in this example:
Enter a symbol: 4
Enter the desired width: 5
44444
4444
444
44
4
Example Python Exercise
Show Python Code
# Prompt the user for a symbol and width
symbol = input("Enter a symbol: ")
width = int(input("Enter the desired width: "))
# Display the triangle with the given symbol and width
for i in range(width, 0, -1):
print(symbol * i)
Output
Case 1:
Enter a symbol: 4
Enter the desired width: 5
44444
4444
444
44
4
Case 2:
Enter a symbol: *
Enter the desired width: 3
***
**
*
Share this Python Exercise