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
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 spacethat evaluates to the persons 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
