128k views
3 votes
An array is said to be dual if it has an even number of elements and each pair of consecutive elements sum to the same value. Return true if the array is dual, otherwise return false.

User Seanysull
by
5.0k points

1 Answer

2 votes

Answer:

def is_dual( array):

if len(array) % 2 == 0:

count = 0

for i in range(0, len(array)//2, 2):

if array[i] + array[i+1] == array[0] + array[1]:

count += 1

if count == len(array)//2:

return True

else:

return False

Step-by-step explanation:

The python program defines a function called is_dual that accepts an array parameter and check if the array is dual. If it meets the condition, the function returns true but returns false when the array is not dual.

User Barden
by
5.4k points