Write a Python program to check whether a given number is a Disarium number or unhappy number


This is a Python program that takes a number as input and checks whether it is a Disarium number or not. The program first prompts the user to enter a number using the input() function, and the int() function is used to convert the input to an integer. The input value is then assigned to the variable num.

The variable temp is initialized to zero. A for loop is used to iterate over each digit of the number. The len() function is used to get the length of the number as a string, and the str() function is used to convert the number to a string. The int() function is used to convert each digit to an integer before raising it to the power of its position in the number, which is calculated as i + 1. The result is added to the temp variable in each iteration of the loop.

After the loop, the temp variable contains the sum of the digits raised to their respective powers. If this sum is equal to the original number num, the program prints a message indicating that num is a Disarium number. Otherwise, the program prints a message indicating that num is not a Disarium number.

Source Code

num = int(input("Enter the Number :"))
temp = 0
for i in range(len(str(num))):
	temp += int(str(num)[i]) ** (i + 1)
 
if temp == num:
	print(num,"is Disarium Number")
else:
	print(num,"is Not Disarium Number")

Output

Enter the Number :56
56 is Not Disarium Number

Example Programs