Answer to Question #262464 in Python for Chiarra

Question #262464

Counting Num

by CodeChum Admin

To give you more of a challenge with a number's digits, let's try counting how many of a certain digit is present on a given number.


Let's start coding!


Instructions:

  1. Input two integer values. The first one shall accept any integer from 0-9 and the other one shall take a non-zero positive integer.
  2. Using a while loop, count how many of the first integer (0-9) is present in the digits of the second inputted integer and print the result (see sample input and output for example).
  3. Tip #1: You have to use your knowledge from the previous problems in looping through the digits of a number: % 10 to get the rightmost digit, while / 10 to remove the rightmost digit. Make sure to solve the previous problems first.

Input

A line containing two integers separated by a space.

2·124218

Output

A line containing an integer.

2





1
Expert's answer
2021-11-08T09:13:50-0500
digit, num = map(int, input().split())
count = 0
while num:
    if num % 10 == digit:
        count +=1
    num = num // 10
print(count)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS