(Math: pentagonal numbers) A pentagonal number is defined as for and so on. So, the first few numbers are 1, 5, 12, 22, .... Write a function with the following header that returns a pentagonal number: def getPentagonalNumber(n): Write a test program that uses this function to display the first 100 pentagonal numbers with 10 numbers on each line

Respuesta :

Answer:

from math import sqrt

def getPentagonalNumber(n):

   return int((3 * n * n - n) / 2)

for p in range(1, 100, 10):

   for x in range(p, p+10):

       print(getPentagonalNumber(x), end=" ")

   print()

Explanation:

The nth pentagonal number can be found by  [tex]\frac{3n^{2} -n }{2}[/tex]

Create a function called getPentagonalNumber that takes one parameter, n and calculates the nth pentagon number using the formula

Create a nested for loop that iterates 100 times. Call the getPentagonalNumber function inside the loop to calculate the first 100 pentagonal number with 10 numbers on each line

ACCESS MORE
EDU ACCESS