Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 5 - Loops - Programming Exercises - Page 161: 5.20

Answer

code

Work Step by Step

# 5.20 (Display four patterns using loops) Use nested loops that display the following # patterns in four separate programs: N = 7 # Pattern A for i in range(1, N): for j in range(1, i + 1): print(j, end=" ") print() print("\n") # Patten B x = N for i in range(1, N): for j in range(1, x): print(j, end=" ") print() x -= 1 print("\n") # Pattern C for i in range(1, N): for j in range(N, i - 1, -1): print(" ", end=' ') for k in range(i, 0, -1): print(k, end=' ') print() print("\n") # Pattern D y = N for i in range(1, N): for j in range(y - 1, 0, -1): print(j, end=" ") print() y -= 1
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.