CMN 152V POST-MIDTERM EXAM
2026 LATEST QUESTIONS AND
ANSWERS| ACE YOUR GRADES.
loopcond1 — try it
For ages below, which version of over21 will run without
producing an error?
ages = [ 18, 24, 22, 17, 20, 21, 19, 18, 20, 25 ]
over21_1 = [ (age > 21) for age in ages ]
over21_2 = [ age for age in ages if (age > 21)]
over21_1
over21_2
Both
Neither - correct answer -both
loopcond2 — try it
For ages below, which version of over21 will produce a list of
numbers?
ages = [ 18, 24, 22, 17, 20, 21, 19, 18, 20, 25 ]
over21_1 = [ (age > 21) for age in ages ]
, Page | 2
over21_2 = [ age for age in ages if (age > 21)]
over21_1
over21_2
Both
Neither - correct answer -over21_2
loopcond3 — try it
For ages below, which version of over21 will produce a list as
long as ages?
ages = [ 18, 24, 22, 17, 20, 21, 19, 18, 20, 25 ]
over21_1 = [ (age > 21) for age in ages ]
over21_2 = [ age for age in ages if (age > 21)]
over21_1
over21_2
Both
Neither - correct answer -over21_1
loopcond4 — try it
Select the option that will produce a list equal to outlist from list
inlist
, Page | 3
inlist = [ 'pinch', 'punch', 'paunch', 'inch', 'cinch', 'wrench' ]
outlist = [ 'pinch', 'inch', 'cinch']
1 [ aword[-5:] == 'inch' for aword in inlist ]
2 [ aword[-4:] == 'inch' for aword in inlist ]
3 [ inchword for inchword in inlist if inchword[-5:] == 'inch' ]
4 [ inchword for inchword in inlist if inchword[-4:] == 'inch' ]
5 [ inch[-5:] for inch in inlist if inch[-5:] == 'nch' ]
6 [ inch[-4:] for inch in inlist if inch[-4:] == 'nch' ]
7 None of the above - correct answer -4
loopcond5 — try it
Select the option that will not produce a list equal to outlist from
list inlist
inlist = [ 'pinch', 'punch', 'paunch', 'inch', 'cinch', 'wrench' ]
outlist = [ 'pinch', 'punch', 'paunch', 'inch', 'cinch', 'wrench' ]
1 [ element for element in inlist if element[-5:-1] == 'inch' ]
2 [ words for words in inlist ]
3 [ val[:] for val in inlist ] - correct answer -1
, Page | 4
loopcond6 — try it
Select the option that will produce a list equal to outlist from list
inlist
inlist = [ 'aardvark', 'apogee', 'ape', 'open', 'oar', 'ocean' ]
outlist = [ 'aardvark', 'oar' ]
1 [ item[2] == 'a' for item in inlist]
2 [ item for item in inlist if item[0] == 'a' ]
3 [ item for item in inlist if item[1] == 'a' ]
4 [ item for item in inlist if item[2] == 'a' ]
5 None of the above - correct answer -3
loopcond7 — try it
Select the option that shows the value of list cantvote
ages = [ 5, 16, 18, 22, 26, 22, 19, 30, 17, 13, 20, 10 ]
cantvote = [ age for age in ages if age < 18 ]
candrivecantvote = [ age for age in ages if age >= 16 ]
print( candrivecantvote )
1 [ 5, 16, 18, 22, 26, 22, 19, 30, 17, 13, 20, 10 ]
2 [ 5, 16, 18, 19, 17, 13, 10 ]
3 [ 5, 16, 18, 17, 13, 10 ]