亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Python3.幾個簡單的for循環(huán)但是沒有輸出,為什么呢?
天蓬老師
天蓬老師 2017-04-17 17:40:03
0
3
675


天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進(jìn)步~~

reply all(3)
黃舟


This is the result of traversing i!=j. You can see that when i=1,j=3 is traversed, the conditions are met and count+1 is reached. At this time, 1 and 3 are removed from list_c Deleted.

Then because two digits were deleted from the front of list_c, the array elements are moved forward by two digits, and j in the next cycle is equal to 6. Then i!=j at this time, and count has become 1 due to the previous cycle. , so the deletion will still be performed this time.

And since 1 has been deleted, list_c.remove(1) will report an error.

a=18
list_c = list(range(1,a+1))
max = list_c[-1] + list_c[-2]
k=[]
for i in range(100):
    if i**2<=max:
        k.append(i**2)
count=0
for i in range(a-1,-1,-1):
    if list_c[i] == 0:
        continue
    for j in range(0,a):
        if list_c[j]==0:
            continue
        if list_c[i] != list_c[j]:
            if list_c[i]+list_c[j] in k:
                print("%s 和 %s配對" % (list_c[i],list_c[j]))
                list_c[i]=0
                list_c[j]=0
                break
劉奇
if i + j in k:
    count += 1

You probably wrote count + 1 by mistake.

黃舟

Brother, I suggest you use a better IDLE. At least it will prompt you if you make a mistake in writing the code. Otherwise, this kind of error would be so boring

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template