0% found this document useful (0 votes)
36 views1 page

Python Lab Program 4

The document describes a program that reads a multi-digit number from the console and prints the frequency of each digit from 0 to 9. It includes a step-by-step algorithm detailing how to count the occurrences of each digit. An example output is provided, demonstrating the program's functionality with the input '122123321'.

Uploaded by

angelotommy006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views1 page

Python Lab Program 4

The document describes a program that reads a multi-digit number from the console and prints the frequency of each digit from 0 to 9. It includes a step-by-step algorithm detailing how to count the occurrences of each digit. An example output is provided, demonstrating the program's functionality with the input '122123321'.

Uploaded by

angelotommy006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LAB-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.

4. Display the header: "Digit Occurrence".


5. Repeat the following steps for each digit i from 0 to 9:

• Initialize count to 0.

• Assign num to a temporary variable temp.

• While temp is greater than 0:

• Get the last digit of temp using temp % 10 and store it in a.

• If a is equal to i, increment count by 1.

• Remove the last digit from temp using integer division (temp = temp //
10).

• If count is greater than 0, print i and count.

6. End

Output:
Enter number: 122123321
Digit Occurrence
1 3
2 4
3 2

You might also like