Generate a code snippet to print a pattern of stars in Python. rows = 5
- User
Generate a code snippet to print a pattern of stars in Python. rows = 5
Assistant
Plan:
- Define the
rowsvariable as given. - Use a
forloop to iterate through the range of numbers from 1 torows. - Inside the loop, print the asterisk character (
*) multiplied by the current loop index to create the widening shape.
Here is the Python code to print a simple right-angled triangle pattern.
# Number of rows rows = 5 # Outer loop for the number of rows for i in range(1, rows + 1): # Inner loop to print stars # We multiply the string '*' by i to get the correct number of stars print("*" * i)Output:
* ** *** **** *****- Define the