Python lab program 4
Python lab program 4
Read a multi-digit number (as chars) from the console. Develop a program to
print the frequency of each digit with suitable message.
num = int(input("Enter number: "))
print("Digit\tOccurrence")
for i in range(10):
count = 0
temp = num
while temp > 0:
a = temp % 10
if a == i:
count += 1
temp = temp // 10
if count > 0:
print(i,"\t\t",count)
Algorithm:
1. Start
2. Prompt the user to input a number.
3. Convert the input to an integer and store it in num.
• Initialize count to 0.
• Remove the last digit from temp using integer division (temp = temp //
10).
6. End
Output:
Enter number: 122123321
Digit Occurrence
1 3
2 4
3 2