Он не возвращает правильный вывод для этого quetiosn.
def crop_hydrated(l): if len(l) == 1 and len([l[0]]) == 1: if l[0][0] == 'w': return True else: False for i,row in enumerate(l[:-1]): for a,col in enumerate(row[:-1]): if col == 'c': if a == 0: if row[a+1] == 'w' or l[i+1][a] == 'w' \ or l[i+1][a+1] == 'w': continue else: return False if a > 0 and i > 0: if row[a-1] == 'w' or row [a+1] == 'w' or \ l[i-1][a-1] == 'w' or l[i-1][a] == 'w' \ or l[i-1][a+1] == 'w' or l[i+1][a-1] == 'w'\ or l[i+1][a] == 'w'\ or l[i+1][a+1] == 'w': continue if a > 0: if row[a-1] == 'w' or l[i+1][a-1] == 'w' or \ l[i+1][a] == 'w' or l[i+1][a+1] == 'w' or row[a+1]: continue else: return False #b = for m,c in enumerate(l[-1][:-1]): if c == 'c': if m == 0: if l[-2][m] == 'w' or l[-2][m+1] == 'w' or\ l[-1][m+1] == 'w': continue else: return False if m > 0: if l[-1][m-1] == 'w' or l[-2][m-1] == 'w' or \ l[-2][m] == 'w' or l[-2][m+1] == 'w' or \ l[-1][m+1] == 'w': continue else: return False return True if __name__ == "__main__": print( crop_hydrated([ [ "w", "c" ], [ "w", "c" ], [ "c", "c" ] ])) ## supposed to return True print(crop_hydrated([ [ "c", "c", "c", "c" ], [ "w", "c", "c", "c" ], [ "c", "c", "c", "c" ], [ "c", "w", "c", "c" ] ])) # supposed to return False print(crop_hydrated([ [ "w", "w" ], [ "w", "c" ], [ "c", "c" ], [ "c", "w" ], [ "c", "w" ] ])) # supposed to return True print(crop_hydrated([ [ "w", "c", "c", "c", "c" ], [ "c", "c", "c", "w", "c" ] ])) # supposed to return True print(crop_hydrated([ [ "c", "w", "w", "w", "c" ], [ "w", "c", "c", "c", "c" ], [ "c", "c", "c", "c", "c" ], [ "w", "c", "c", "w", "c" ] ])) # supposed to return True 4 print(crop_hydrated([ [ "c", "c", "w", "c", "c", "w" ], [ "c", "w", "c", "c", "c", "c" ], [ "c", "c", "c", "c", "c", "c" ], [ "c", "c", "c", "w", "c", "c" ], [ "c", "c", "c", "c", "w", "c" ], [ "c", "c", "c", "c", "c", "c" ], [ "c", "c", "c", "c", "c", "c" ], [ "c", "c", "c", "c", "c", "c" ] ])) # supposed to return False print(crop_hydrated([ [ "w", "w", "c", "c", "w" ], [ "c", "c", "c", "c", "c" ], [ "c", "c", "w", "c", "c" ], [ "w", "c", "c", "w", "w" ], [ "c", "c", "w", "c", "c" ], [ "c", "c", "w", "c", "c" ], [ "c", "c", "c", "w", "c" ] ])) # supposed to return False
Что я уже пробовал:
я пытаюсь решить этот вопрос с сайта по ссылке https://edabit.com/challenge/FmowTJecDKQMRqsHS[^]
но это не дает мне правильного выхода, который они мне желают: