Write a Python program to get the nth tetrahedral number from a given integer(n) value


This Python program calculates the nth Tetrahedral Number, given a user input n as an integer. A Tetrahedral Number is the sum of the first n triangular numbers, where a triangular number is the sum of the first n natural numbers. The program uses the formula for calculating the nth Tetrahedral Number, which is given by (n * (n + 1) * (n + 2)) / 6.

First, the program prompts the user to enter the value of n using the input() function, and converts the input to an integer using the int() function. The program then calculates the nth Tetrahedral Number using the formula and stores the result in the variable res. Finally, the program prints the result to the console using the print() function along with an appropriate message, "Tetrahedral Number:".

Source Code

n = int(input("Enter the Number :"))
res = ((n * (n + 1) * (n + 2)) / 6)
print("Tetrahedral Number:",

Output

Enter the Number :23
Tetrahedral Number: 2300.0

Example Programs