Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我试着运行这个,它说;int对象不可下标";第16行_Python - Fatal编程技术网

Python 我试着运行这个,它说;int对象不可下标";第16行

Python 我试着运行这个,它说;int对象不可下标";第16行,python,Python,ISBN代码检查器的程序 code=str(input("Please enter the ISBN code. ")) incode=0 modul=0 sumcode=0 subt=0 count=0 multvar=1 codelist2=[] if len(code)!=13: print("Invalid ISBN code.") elif code.isdigit() and len(code)==13: codelist=list(code) code=in

ISBN代码检查器的程序

code=str(input("Please enter the ISBN code. "))
incode=0
modul=0
sumcode=0
subt=0
count=0
multvar=1
codelist2=[]
if len(code)!=13:
    print("Invalid ISBN code.")
elif code.isdigit() and len(code)==13:
    codelist=list(code)
    code=int(code)
    for i in range (12):
        if multvar==1:
            codelist.append(code[count]*1)  # This is where the Python Shell says there is an error
            multvar+=1
            count+=1
        elif multvar==2:
            codelist.append(code[count]*3)
            multvar-=1
            count+=1
    sumcode=sum(codelist)
    modul=sumcode%10
    subt=10-modul
    if subt==codelist[12]:
        print("Valid ISBN code.")
    else:
        print("Invalid ISBN code.")

我已经试着修复这个问题有一段时间了,我认识的人中没有人能帮我修复这个错误

我几乎成功了

code=str(input("Enter an ISBN code to check if it's valid. Please make sure you add spaces between each number. "))
incode=0
modul=0
sumcode=0
subt=0
count=0
multvar=1
codelist=code.split()
while True:
    codelist[count]=int(codelist[count])
    count+=1
    if count==13:
        break
if len(code)!=13:
    count=0
    print("Invalid ISBN code.")
elif code.isdigit() and len(code)==13:
    for i in range (12):
        if multvar==1:
            codelist.append(code[count])
            multvar+=1
            count+=1
        elif multvar==2:
            codelist.append(code[count]*3)
            multvar-=1
            count+=1
        sumcode=sum(codelist)
        modul=sumcode%10
        subt=10-modul
        if subt==codelist[12]:
            print("Valid ISBN code.")
        else:
            print("Invalid ISBN code.")

您只能对列表和其他可编辑对象使用
[]
表示法。不是整数。你这样做想达到什么目的?
code=int(code)
然后
code[count]*1
就没有意义了。首先,你想对伯爵说什么?如果是精确的数字,请将代码改为'str'秒。为什么要将任何值乘以1?这看起来应该是对你的问题的编辑,而不是答案。