Introduction to Programming using Python 1st Edition

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

Chapter 6 - Functions - Programming Exercises - Page 204: 6.6

Answer

code

Work Step by Step

# 6.6 (Display patterns) Write a function to display a pattern as follows: # 1 # 2 1 # 3 2 1 # ... # n n-1 ... 3 2 1 # The function header is # def displayPattern(n): # Write a test program that prompts the user to enter a number n and invokes # displayPattern(n) to display the pattern. def displayPattern(n): for i in range(1, n + 1): for j in range(n, i - 1, -1): print(format(" ", "2s"), end=" ") for j in range(i, 0, -1): print(format(j, "2d"), end=" ") print() n = eval(input("Enter an integer: ")) displayPattern(n)
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.