Narcissistic number | Python program for checking of Narcissistic number ; Traversing through the string ; Converting character to int ; Converting string to integer ; Comparing number and sum ; Driver Code taking input as string
def getResult ( st ) : NEW_LINE INDENT sum = 0 NEW_LINE length = len ( st ) NEW_LINE for i in st : NEW_LINE INDENT sum = sum + int ( i ) ** length NEW_LINE DEDENT number = int ( st ) NEW_LINE if ( number == sum ) : NEW_LINE INDENT return " true " NEW_LINE DEDENT else : NEW_LINE INDENT return " false " NEW_LINE DEDENT DEDENT st = "153" NEW_LINE print ( getResult ( st ) ) NEW_LINE