简体   繁体   中英

ValueError: invalid literal for int() with base 10: '7 1 3 4 1 7' . Hackerrank question showing error

'''

listSize=int(input())
arrayList=list()
dist=listSize
k=int
i=int
for i in range(1,listSize):
    arrayNo=int(input())
    arrayList.append(arrayNo)
for i in range(1,listSize):
    k=i+1
    for k in range(1,listSize):
        if(arraylist[i]==arrayList[k]&k-i<dist):
            dist=k-i
        k+=1
    i+=1
print(dist)

'''

I'm getting an error Main que is: Print out the minimum difference of indices having same value element value Traceback (most recent call last):

  File "Solution.py", line 7, in <module>

    arrayNo=int(input())

ValueError: invalid literal for int() with base 10: '7 1 3 4 1 7'

Your argument to int() is a string that contains multiple "integers" separated by spaces. Look at documentation for the split() method on strings to split your input into the pieces you want, then apply int() on them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM