Python program to find the Nth Decagonal Number
In this article, we will learn how to find the nth Decagonal Number in Python. But first, let’s learn a few points about Decagonal Numbers.
formula of decagonal numbers
D(n) = 4*n^2 – 3*n
The Decagonal numbers are 0, 1, 10, 27, 52, 85, 126, 175, 232,….
Find the Nth Decagonal Number in Python
1. Firstly, get the user input n.
2. Create a function DecagonalNumber with n as an argument
- Now apply the formula 4*n*n – 3*n and return the result.
def DecagonalNumber(n): return (4*n*n - 3*n) n = int(input("Enter the n value: ")) print("The Decagonal Number is: ", DecagonalNumber(n))
Enter the n value: 5 The Decagonal Number is: 85 Enter the n value: 10 The Decagonal Number is: 370 Enter the n value: 115 The Decagonal Number is: 52555