0
267views
Write a python program to count the occurrence of a element

Problem: in this first line you are required to take the input of an integer number, and in the second line you are required to input the target element

You are required to print the number of time target element occurred in the integer

1 Answer
0
1views

Test Case :

Input :
734139
3
Output :
2

Explanation : 3 occurred 2 times in the integer.

Code in Python

n=int(input())

x=int(input())

c=0

for i in str(n):

    if int(i)==x:

        c+=1


print(c)

Note:-

  • As we cannot iterate over a integer we have converted it into a string
  • then converted …

Create a free account to keep reading this post.

and 2 others joined a min ago.

Please log in to add an answer.