mercredi 29 janvier 2020

Conditional statement on None in Python

PFB the program. In that we have a condition block if curr > max_v or max_v == None:. This is giving an error

TypeError: '>' not supported between instances of 'int' and 'NoneType'

However, if I change the condition to max_v == None or curr > max_v: it works fine. What is the issue here. Please advice.

arr_ele = []

for arr_i in range(6):
    arr_t = [int(arr_temp) for arr_temp in input().strip().split()]
    arr_ele.append(arr_t)

length = len(arr_ele[0])


max_v = None
curr = 0
for i in range(length-2):
    for j in range(length-2):
        curr = arr_ele[i][j] + arr_ele[i][j+1] + arr_ele[i][j+2] + \
               arr_ele[i+1][j+1] + \
               arr_ele[i+2][j] + arr_ele[i+2][j+1] + arr_ele[i+2][j+2]


        if  curr > max_v or max_v == None:
            max_v = curr

print(max_v)

Aucun commentaire:

Enregistrer un commentaire