Download Quiz 4 with solutions, 17 Sep 2014

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Name:
Introduction to Programming in Python, I Semester, 2014–2015
Quiz 4, 17 September 2014
1. Complete the following recursive definition to reverse a list. Insert exactly one expression for each of the return statements.
def myreverse(l):
if l == []:
return (
l
else:
return ( l[-1:] + myreverse(l[:-1])
)
)
(5 marks)
2. What is the value of pairs after the following assignment?
pairs = [ (x,y) for x in range(4) for y in range(3) if (x+y)%2 != 0 ]
(5 marks)
pairs : [(0, 1), (1, 0), (1, 2), (2, 1), (3, 0), (3, 2)]