Write a predicate function called same_ends that accepts a list of integers and an integer (n) as arguments. Return True if the first n numbers in the list are the same as the last n numbers in the list, and False otherwise. For example, if the list was [1, 2, 3, 4, 99, 1, 2, 3, 4], the function would return True if n is 4 and False if n is 3. Assume that n is between 1 and the length of the list, inclusive. Solve It!

Respuesta :

Answer:

5=5

Explanation:

2+2 is 4

Below is the required Python code for the program.

Python

Program code:

# Starting the code

# Defining a function

def same_ends(lst, n):

   # Starting a loop

   if lst[:n] == lst[-n:]:

       return True

   else:

       return False

# Testing the function

lst = [1, 2, 3, 4, 99, 1, 2, 3, 4]

# Printing the values

print(same_ends(lst,4))

print(same_ends(lst,3))

Explanation:

  • Starting the code.
  • Defining a function.
  • Starting a loop.
  • Testing the function.
  • Printing the values.
  • End up a code.

Output:

Find below the attachment of the code output.

Find out more information about python here:

https://brainly.com/question/26497128

Ver imagen Cricetus