您好,我有一个序列号,例如 204567,这 6 个数字中的每个数字都有子集数据。有没有一种方法可以通过 python 中的每个数字进行加密?
1 回答
梵蒂冈之花
TA贡献1900条经验 获得超5个赞
from math import floor
def check_if_number_exists(number, digit_to_find):
# check if the number is positive
if number < 0:
Number = -number
else:
Number = number
while(Number != 0):
# run loop for extracting each digit
Digit = Number % 10 # gives the last number
Number = floor(Number / 10) # removing the last digit
if Digit == digit_to_find:
print("the number contains " + str(digit_to_find) + ' in ' + str(number))
break
# sequencenumber, number_to_check
check_if_number_exists(45638, 3)
还有另一种方法,您可以将数字转换为字符串,然后检查字符串的每个元素!
添加回答
举报
0/150
提交
取消