Делаю каты на codewars и столкнулся с проблемой: все тесты пройдены, кроме 2, не понимаю почему так.
def is_smooth(arr):
start_of_arr = arr[0]
final_of_arr = arr[-1]
len_of_arr = len(arr)
if len_of_arr > 2:
if len_of_arr % 2 == 0:
list_of_medium_n = []
len_final_length = 2
rigth_length = (len_of_arr - len_final_length) / 2
left_length = (len_of_arr - len_final_length) / 2
rigth_length = int(-rigth_length)
left_length = int(left_length)
for i in arr:
list_of_medium_n.append(i)
final_medium_n = list_of_medium_n[left_length:rigth_length]
sum_final_medium_n = sum(final_medium_n)
if sum_final_medium_n == start_of_arr:
if sum_final_medium_n == final_of_arr:
return True
else:
return False
else:
return False
else:
list_of_medium_n = []
len_final_length = 1
rigth_length = (len_of_arr - len_final_length) / 2
left_length = (len_of_arr - len_final_length) / 2
rigth_length = int(-rigth_length)
left_length = int(left_length)
for i in arr:
list_of_medium_n.append(i)
final_medium_n = list_of_medium_n[left_length:rigth_length]
if final_medium_n == start_of_arr:
if final_medium_n == final_of_arr:
return True
else:
return False
else:
return False
else:
return False
print(is_smooth([7, 2, 2, 5, 10, 7])) # must be True)
print(is_smooth([-12, 34, 40, -5, -12, 4, 0, 0, -12])) # must be True)
print(is_smooth([-5, -5, 10])) # must be False
print(is_smooth([4, 2])) # must be False
print(is_smooth([45, 23, 12, 33, 12, 453, -234, -45])) # must be False
print(is_smooth([9, 0, 15, 9])) # must be False
print(is_smooth([-6, 6, -6])) #must be False
print(is_smooth([26, 26, -17])) # must be False
print(is_smooth([-7, 5, 5, 10])) # must be False
print(is_smooth([3, 4, 5])) # must be False
print(is_smooth([-5, 3, -1, 9])) # must be False
https://repl.it/repls/UnlinedSpatialEmulation