65.6k views
5 votes
Problem 2 Write a program that uses a nested loop to display Pattern A below, followed. by another nested loop that displays Pattern B.

Pattern A:
Pattern B:

(1) Your program code:
[copy and paste your program here, and keep indentation to make your code readable] Code for pattern A:
Code for pattern B:
(2) The result of running your code:
[paste the screenshot of the running result] Screenshot for Pattern A:
Screenshot for Pattern B:

User Opmet
by
7.1k points

1 Answer

2 votes

Final answer:

To display Pattern A and Pattern B using nested loops in Python, you can use the provided code. Run the code to see the output.

Step-by-step explanation:

Pattern A:

In order to display Pattern A using a nested loop, you can use the following Python code:

for i in range(1, 6):
for j in range(1, i+1):
print(j, end=' ')
print()

Pattern B:

To display Pattern B using a nested loop, you can use the following Python code:

for i in range(1, 6):
for j in range(1, 6-i+1):
print(j, end=' ')
print()

Screenshot for Pattern A:

Unfortunately, I cannot provide a screenshot in the text-based format, but you can copy and run the code to see the output.

Screenshot for Pattern B:

Similarly, you can run the code provided for Pattern B to see the output.

User Ferrybig
by
8.4k points