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 203: 6.1

Answer

The answer is below.

Work Step by Step

Write a test program that uses this function to display the first 100 pentagonal numbers with 10 numbers on each line. $Code:$ def getPentagonalNumber(n): $ $ $ $ $ $ $ $ $ $ return (n*(3*n-1))/2 print("The first 100 pentagonal numbers are:") for i in range(1,101): $ $ $ $ $ $ $ $ $ $ print("{}".format(getPentagonalNumber(i))) $ $ $ $ $ $ $ $ $ $ if i%10==0: $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ print("\n") $Output:$ The first 100 pentagonal numbers are: 1.0 5.0 12.0 22.0 35.0 51.0 70.0 92.0 117.0 145.0 176.0 210.0 247.0 287.0 330.0 376.0 425.0 477.0 532.0 590.0 651.0 715.0 782.0 852.0 925.0 1001.0 1080.0 1162.0 1247.0 1335.0 1426.0 1520.0 1617.0 1717.0 1820.0 1926.0 2035.0 2147.0 2262.0 2380.0 2501.0 2625.0 2752.0 2882.0 3015.0 3151.0 3290.0 3432.0 3577.0 3725.0 3876.0 4030.0 4187.0 4347.0 4510.0 4676.0 4845.0 5017.0 5192.0 5370.0 5551.0 5735.0 5922.0 6112.0 6305.0 6501.0 6700.0 6902.0 7107.0 7315.0 7526.0 7740.0 7957.0 8177.0 8400.0 8626.0 8855.0 9087.0 9322.0 9560.0 9801.0 10045.0 10292.0 10542.0 10795.0 11051.0 11310.0 11572.0 11837.0 12105.0 12376.0 12650.0 12927.0 13207.0 13490.0 13776.0 14065.0 14357.0 14652.0 14950.0 Compiler code is below
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.