



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Part I—Vocabulary Matching
____6______Mutable
_____5_____Float
_____3_____Syntax Error
______10____Increment
_____14_____Function
_____4_____Integer
_____1_____Runtime Error
____7______Immutable
_____8_____Recursion
_____12_____Linear Search
_____11_____Insertion Sort
_____15_____Parameters
_____13_____Variable
_____9_____Slice
_____2_____Semantic Error
Part II—Writing Code
For example, countByTwo(1, 12) would print 1, 3, 5, 7, 9, 11.
def countByTwo(a,b): i=a while i < b: print i i+=
For example, combineList(aList, bList) would return [4,5,6,1,2,3] if aList=[4,5,6] and bList=[1,2,3].
def combineList(aList, bList): newList= aList + bList return newList
Part III—Interpreting Code
a = [1, 36, [“Puppy”, “Kitten”], 29, [12.1, 33.3], 21] b = a[2:] c =b[::] d = a[2][0] d = “Dog”
b [['Puppy', 'Kitten'], 29, [12.1, 33.299999999999997], 21]_
c [['Puppy', 'Kitten'], 29, [12.1, 33.299999999999997], 21]_
d ____________________Dog_________________________________________
a[1] _____________________36________________________________________
a[1] + b[1] _______________________65______________________________________
c[‐3] __________________________________29___________________________
d + “house” _______________________Doghouse_________________________________
var1= 15 def foo(): var2= var1= print var
print foo() var2= var2 + 1 print var
What is outputted when the code runs?
12, An error message
def filterOutEvens(list): newList= [] for element in list: if element % 2 == 0: newList.append(element) return newList
aList = [2, 4, 5, 5, 7, 6, 10] print filterOutEvens(aList)
Part IV—Extra Credit
44
23
Sonny
Answers may vary
Answers may very