我正在尝试检查短整数是否具有包含长整数的数字。取而代之的是:
long int: 198381998
short int: 19
Found a match at 0
Found a match at 1
Found a match at 2
Found a match at 3
Found a match at 4
Found a match at 5
Found a match at 6
Found a match at 7
它应该看起来像这样:(正确的一个)
long int: 198381998
short int: 19
Found a match at 0
Found a match at 5
代码:
longInt = ( input ("long int: "))
floatLong = float (longInt)
shortInt = ( input ("short int: "))
floatShort = float (shortInt)
max_digit = int (math.log10(floatLong)) #Count the no. of long int
i = int(math.log10(floatShort)) # Count the no. shortInt that is being input
for string in range (max_digit):
if ( shortInt in longInt): # Check whether there is any digit in shortInt
# that contains anything inside longInt
print ( "Found a match at ", string)
不使用 python 的任何内置函数,没有 list 或 string.etc 方法。