53.5k views
1 vote
2.24 Write the relevant Python expression or statement, involving a list of numbers lst and using list operators and methods for these specifications: (a) An expression that evaluates to the index of the middle element of lst (b) An expression that evaluates to the middle element of lst (c) A statement that sorts the list lst in descending order (d) A statement that removes the first number of list lst and puts it at the end 2.25 Add a pair of parentheses to each expression so that it evaluates to True. (a) 0 == 1 == 2 (b) 2 + 3 == 4 + 5 == 7 (c) 1 < -1 == 3 > 4 For each expression, explain i

1 Answer

6 votes

Answer:

lst = [11, 603, 99, 7, 582, 1];

print("The index of the middle element: " + str(int(len(lst)/2)))

print("The middle element: " + str(lst[int(len(lst)/2)]))

lst.sort()

sorted_lst = lst.reverse()

print("The list in descending order: " + str(lst))

first_number = lst.pop(0)

lst.append(first_number)

print("New lst: "+ str(lst))

Step-by-step explanation:

- Initialize a list

- Find the middle index, int(len(lst)/2)

- Find the middle element, lst[int(len(lst)/2)]

- Sort the list in descending order (First sort the list in ascending order than reverse it)

- Get the first element using pop method, and append it to the end using append method

- - - - -

a) 0 == 1 == 2 --> Always evaluates false

b) 2 + (3 == 4) + 5 == 7 --> Evaluates true

c) 1 < -1 == 3 > 4 --> Always evaluates false

User Andres S
by
6.2k points