Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write Python expressions corresponding to these statements: 2.22 Write an expres

ID: 3738941 • Letter: W

Question

Write Python expressions corresponding to these statements:

2.22 Write an expression involving string s containing the last and first name of a person— separated by a blank space—that evaluates to the person’s initials. If the string contained my first and last name, the expression would evaluate to 'LP'.

2.23 The range of a list of numbers is the largest difference between any two numbers in the list. Write a Python expression that computes the range of a list of numbers lst. If the list lst is, say, [3, 7, -2, 12], the expression should evaluate to 14 (the difference between 12 and -2).

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 in what order the operators were evaluated

Explanation / Answer

#2.22 s = "Ljubomir Perkovic" names = s.split() initial = "" for i in names: initial += i[0] print(initial) #2.23 l = [3, 7, -2, 12] print(max(l) - min(l)) #2.24 l1 = [3, 7, 17, -2, 12] #(a) midIndex = int(len(l1)/2) print(midIndex) #(b) print(l1[midIndex]) #(c) l1.sort(reverse=True) print(l1) #(d) firstValue = l1[0] l1 = l1[1:] + [firstValue] print(l1) #2.25 #(a) if 0 == 1 == 2: #compares 0 == 1 == 2 and returns false print("True") else: print("False") #(b) if 2 + 3 == 4 + 5 == 7: #adds 2+3 compares with 4+5 and compares with 7 returns false print("True") else: print("False") #(c) if 1 < -1 == 3 > 4: #compares -1 == 3 first returns false print("True") else: print("False")
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote