Search and Find the Key in Python

#---------------------------- search for key from given number ----------------------------

# -------- find one digit -------

num = int(input("Enter a numer : "))
key = int(input("Enter key to search :"))
while(num>0):
    ld = num % 10
    num = num//10
    if(ld == key):
        print(key,"exists!")
        break
if(ld != key):
    print(key,"does not exists.")
#---------------------------- search for key from given number ----------------------------

# -------- two digit -------

num = int(input("Enter a numer : "))
key = int(input("Enter key to search :"))
while(num>0):
    ld = num % 100
    num = num//10
    if(ld == key):
        print(key,"exists!")
        break
if(ld != key):
    print(key,"does not exists.")
#---------------------------- search for key from given number ----------------------------

# -------- find three digit -------

num = int(input("Enter a numer : "))
key = int(input("Enter key to search :"))
while(num>0):
    ld = num % 1000
    num = num//10
    if(ld == key):
        print(key,"exists!")
        break
if(ld != key):
    print(key,"does not exists.")
#---------------------------- search & count for key from given number -----------------------

num = int(input("Enter a number: "))
key = int(input("Enter key to search: "))
count = 0

while num > 0:
    ld = num % 10     # n % 100 for two digits
    num = num // 10
    if ld == key:
        count += 1

if count > 0:
    print(key, "exists!")
    print("Repeats for", count, "times")
else:
    print(key, "does not exist.")

Join our team, where career growth knows no limits.

For More Details

Our internship program guarantees personalized attention for optimal career development in the tech industry.

+91 97879 68375

-> You should bring your own laptop during the internship

Who can apply?

Internships are open for students who: B.E / B.Tech / M.E / M.Tech / B.Sc / M.Sc / M.C.A / B.C.A / Diploma.

  • Ongoing Students Only
  • days, 5days/ 10days or Based on Student Preference
  • Limited 1 to 10 students per slot
  • Registration fees : 1000 INR
  • Slots are filling quickly only fewer slots are available