猿问

Python数据分析序号

您好,我有一个序列号,例如 204567,这 6 个数字中的每个数字都有子集数据。有没有一种方法可以通过 python 中的每个数字进行加密?



HUX布斯
浏览 77回答 1
1回答

梵蒂冈之花

from math import floordef check_if_number_exists(number, digit_to_find):&nbsp; &nbsp; # check if the number is positive&nbsp; &nbsp; if number < 0:&nbsp; &nbsp; &nbsp; &nbsp; Number = -number&nbsp; &nbsp; else:&nbsp; &nbsp; &nbsp; &nbsp; Number = number&nbsp; &nbsp; while(Number != 0):&nbsp; &nbsp; &nbsp; &nbsp; # run loop for extracting each digit&nbsp; &nbsp; &nbsp; &nbsp; Digit = Number % 10 # gives the last number&nbsp; &nbsp; &nbsp; &nbsp; Number = floor(Number / 10) # removing the last digit&nbsp; &nbsp; &nbsp; &nbsp; if Digit == digit_to_find:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("the number contains " + str(digit_to_find) + ' in ' + str(number))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sequencenumber, number_to_check&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;check_if_number_exists(45638, 3)还有另一种方法,您可以将数字转换为字符串,然后检查字符串的每个元素!
随时随地看视频慕课网APP

相关分类

Python
我要回答