-2

short int に long int を含む数字があるかどうかを確認しようとしています。代わりにこれが出てきました:

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メソッドを使用しません。

4

2 に答える 2