[Solved] Basic Python, checking if a certain interger is in a larger number [closed]


You need to do string comparisons, an example is shown below:

import random
for x in range(10):
  myNum = random.randint(1,101)
  if "5" in str(myNum):
      print("5 is in " + str(myNum))
  else:
      print("5 not in "+ str(myNum))

obviously, 5 could be any number you’d like, if however you want to check if 4564 and 2126 contain the same numbers here’s what you could do.

num1list = []
num2list = []
num1 = "4564"
num2 = "2126"
for num in num1:
    num1list.append(num)
for num in num2:
    num2list.append(num)
#Now we have lists with individual digits
# traverse in the 1st list
for element in num1list:
    if element in num2list:
        print(element+" is present in both lists")

this would return the following:
6 is present in both lists

an example output is shown below from the first section of code.

5 not in 97

5 not in 8

5 not in 93

5 not in 6

5 is in 25

5 not in 20

5 not in 97

5 not in 1

5 not in 81

5 not in 100

0

solved Basic Python, checking if a certain interger is in a larger number [closed]