Find the frequency of each digit in a number.

In this program, we will find the frequency of each digit in a given integer.

Steps to solve the program
  1. Take a number as input and convert it into a string using str() and store it in another variable.
  2. Create an empty dictionary.
  3. Use for loop to iterate over each digit of the number and digit as key and its occurrences as the value in the dictionary.
  4. Print the output
				
					num = 12312543
str1 = str(num)
dict1 = {}

for val in str1:
    if val in dict1: 
       dict1[val] += 1:
    else:
       dict1[val] = 1
    
    
print(dict1)
				
			

Output :

				
					{'1': 2, '2': 2, '3': 2, '5': 1, '4': 1}
				
			

check whether a number is a palindrome or not

enter a number and print it in words

Leave a Comment