WHILE LOOP: =========== # WAP TO COUNT THE NUMBER OF DIGITS IN A GIVEN NUMBER. # for the counting of digits in number, no method is available. # convert a number ==> string # find the length of the string ==> count digits of number num = int(input("Enter a value:")) num_str = str(num) # convert a number into a string print(type(num)) print(type(num_str)) """ len() ==> pre-defined method used to find the number of characters in a given string. Syntax: len|(str_data) """ print("The number of digits of",num,"is = ",len(num_str)) =================================== # WAP IN PYTHON TO CHECK WHETHER THE GIVEN NUMBER IS PALINDROME NUMBER OR NOT. """ NUMBER FIND REVERSE REVERSE = 0 REVERSE = REVERSE * 10 + IND_DIG REVERSE == NUMBER ==> PALINDROME NUMBER 1 x 10 = 10 10 x 10 = 100 100 x 10 = 1000 """ num = int(input("Enter a decimal value:")) # 1221 n = num # n = 1221 rev_num = 0 while n != 0: ind_dig = n % 10 # 1 2 2 1 rev_num = rev_num * 10 + ind_dig # 1221 n //= 10 # 122//10 ==> 12//10 ==> 1//10 ==> 0 if rev_num == num: print(num,"is a palindrome number.") else: print(num,"is not a palindrome number.") ========================== # WAP TO FIND WHETHER A GIVEN NUMBER IS ARMSTRONG NUMBER OR NOT. """ 3-DIGIT: XYZ X^3 + Y^3 + Z^3 == XYZ ==> ARMSTRONG NUMBER 4-DIGIT: ABCD A^4 + B^4 + C^4 + D^4 == ABCD """ num = int(input("Enter a number:")) # 1234 cnt_dig = len(str(num)) # 4 n = num # n = 1234 s_dig = 0 while n > 0: ind_dig = n % 10 # 4 3 2 1 powers = ind_dig ** cnt_dig # 64 81 16 1 s_dig += powers # 64 + 81 + 16 + 1 n //= 10 # 123//10 == 12//10 == 1//10 == 0 if s_dig == num: print(num, "is an armstrong number.") else: print(num, "is not an armstrong number.")