简体   繁体   中英

variable to call list value - python

I need my game to run this:

def w_win(l,l2,check):
    line = l
    line2 = l2
    for x in range(4):
        if line[x] == line2[x]:
            if len(str(check+check)) == 1:
                line[x] = "  "+str(check+check)+" "
            if len(str(check+check)) == 2:
                line[x] = "  "+str(check+check)+""
            if len(str(check+check)) == 3:
                line[x] = " "+str(check+check)
            if len(str(check+check)) == 4:
                line[x] = str(check+check) 

but then I get this:

if line[x] == line2[x]:

TypeError: 'NoneType' object has no attribute '__getitem__'

and I'm calling with

for p in range(2,1025):

    first = w_win([" ","2","16"," "],[" ","2"," ","32"],p)

any help?

Your w_win function is missing the return statement which is required when you are assigning the function's value to the variable 'first'. In your case the variable first is initialized to Class of 'NoneType' because of missing return statement.

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