Exercise
Northeast Triangle
Objective
Develop a Python program that prompts the user for a width and displays a triangle like this one:
Enter the desired width: 5
*****
_****
__***
___**
____*
Example Python Exercise
Show Python Code
# Prompt the user for the desired width of the triangle
width = int(input("Enter the desired width: "))
# Loop through each row from 0 to width-1
for i in range(width):
# Print leading underscores
print('_' * i + '*' * (width - i))
Output
Case 1:
Enter the desired width: 5
*****
_****
__***
___**
____*
Case 2:
Enter the desired width: 3
***
__**
___*
Share this Python Exercise
More Python Programming Exercises of Python Data Types
Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.
This Python program prompts the user to enter a number and then displays that number as a product of its prime factors. The program uses a factorization approa...
This Python program prompts the user to enter a symbol and determines whether it is an uppercase vowel, a lowercase vowel, a digit, or any other ...
This Python program uses a "for" loop to print the uppercase letters from "B" to "N". By utilizing Python's range() function and specifying the A...
This Python program calculates an approximation for PI using the series expression: pi/4 = 1/1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 ... The program allows t...
This Python program calculates the perimeter, area, and diagonal of a rectangle based on its width and height. The program prompts ...
This Python program prompts the user to enter a number and then displays its equivalent values in both hexadecimal and binary formats. The program conti...