midterm-2-key

# Mark which kind of statement can be used to skip code

This preview shows pages 12–14. Sign up to view the full content.

Question 26 [1 mark] Which kind of statement can be used to skip code? A. Assignment statement. B. Conditional statement. = ANS C. Print statement. D. Function definition. E. All of the above. Question 27 [1 mark] Consider the following Python compound statement: if x == 0: y = 1 elif x == 1: y = -1 else: y = 0 Which Python code is this statement not equivalent to? continued on page 13

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
ENG 1D04 SOLUTIONS 13/14 Question 28 [1 mark] Consider the following Python code where L1 is bound to some list: L2 = [] for x in L1: L2 = L2 + [x] print L2 When this code is executed, what is printed? continued on page 14
ENG 1D04 SOLUTIONS 14/14 Question 29 [1 mark] Consider the following function defined in Python def f(a): x = a[0] for i in range(len(a)): if a[i] < x: x = a[i] return x Assuming a is a nonempty list of floats, what is the value of f(a) ? Question 30 [1 mark] Consider the following Python program where S is an unspecified statement: x = [0] for i in range(5): S print x What should the statement S be to guarantee that the program prints [0, [0, [0, [0, [0, [0]]]]]] A. x = [x] . B. x = [0] + x . C. x = [0] + [x] . = ANS D. x[0] = [0] . E. x[1] = [0] . Please make sure your version number is clearly marked on your scan sheet! THE END.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern