22C:16 CS:1210 Exam 2
April 5th, 6:30 pm to 8:30 pm
Instructions:
This is an open notes exam and you have 2 hours to complete it. There are 4 problems in
the exam and these appear on 8 pages.
Make sure that you do not have any electronic devices (laptop
22C:16 CS:1210 Exam 1
Feb 22nd, 6:30 pm to 8:30 pm
Instructions:
This is an open notes exam and you have 2 hours to complete it. There are 4 problems in
the exam and these appear on 7 pages.
Make sure that you do not have any electronic devices (laptops
22C:16 (CS:1210) Quiz 8
You have 20 minutes to complete this quiz.
1. Suppose that D is the dictionary cfw_"what": "why", "are": "what", "you": "what",
"why": "hello", "next": "are", "hello": "next". Given below are a bunch of
expressions. Write down what
22C:16 (CS:1210) Quiz 7
You have 20 minutes to complete this quiz.
Evaluate each expression and write down its value. Assume that (i) grow is a function that takes
two parameters a and b and returns [a]*b, (ii) isLen2 is a function that takes a parameter
22C:16 (CS:1210) Quiz 6
You have 20 minutes to complete this quiz.
1. Dene a function called moveNegatives that takes a list L of integers as a parameter.
The function is required to return a new list obtained by moving all the negative integers in L to t
22C:16 (CS:1210) Quiz 6
You have 20 minutes to complete this quiz.
1. We want to write a function notNeighbors that takes two words word1 and word2 as
parameters and returns True if word2 cannot be obtained from word1 by substituting
exactly one letter by
22C:16 (CS:1210) Quiz 5
You have 20 minutes to complete this quiz.
1. Consider the following function denition.
def test(a, b, c = 20, d = "12"):
return str(b) + str(c) + d + a
For each of the function calls below, rst write down if the function call caus
22C:16 (CS:1210) Quiz 5
You have 20 minutes to complete this quiz.
1. Consider the following function denition.
def test(a, b, c = 20, d = "12"):
return str(b) + str(c) + d + a
For each of the function calls below, rst write down if the function call caus
22C:16 (CS:1210) Quiz 5
You have 20 minutes to complete this quiz.
1. Consider the following function denition.
def test(a, b = 0, c = 2, d = "12"):
return str(a - c) + d + str(b)
For each of the function calls below, rst write down if the function call c
22C:16 (CS:1210) Quiz 3
You have 20 minutes to complete this quiz.
1. Suppose that variable x has value 18 and variable y has value 13. Evaluate each of the
following boolean expressions.
(a) (x != y) and (x < y)
(b) (x < 15) and (15 > y)
(c) not(not(x %
22C:16 (CS:1210) Quiz 2
You have 20 minutes to complete this quiz.
1. Write down the output produced by the following program:
n=5
m=2
while m <= n:
if (m * n) % 4 = 0:
print "Line 1", n, m
m=m+1
else:
print "Line 2", n, m
n=n+1
m=m+2
2. Write a program t
22C:16 (CS:1210) Quiz 2
You have 20 minutes to complete this quiz.
1. Write down the output produced by the following program:
n=6
m=3
while (n - m) < 6:
if (m * n) % 4 = 0:
print "Line 1", n, m
m=m-1
print "Line 2", n, m
n=n+1
2. Write a program that rea
22C:16 (CS:1210) Quiz 1
You have 20 minutes to complete this quiz.
1. This is our rst Python program, intToBinary1.py. What output does it produce for
input 22?
n = int(raw_input("Type a nonnegative integer. ")
while n > 0:
print n%2
n = n/2
2. Consider t
22C:16 (CS:1210) Quiz 1
You have 20 minutes to complete this quiz.
1. This is our rst Python program, intToBinary1.py. What output does it produce for
input 19?
n = int(raw_input("Type a nonnegative integer. ")
while n > 0:
print n%2
n = n/2
2. Consider t
22C:16 (CS:1210) Quiz 1
You have 20 minutes to complete this quiz.
1. This is our rst Python program, intToBinary1.py. What output does it produce for
input 21?
n = int(raw_input("Type a nonnegative integer. ")
while n > 0:
print n%2
n = n/2
2. Consider t
22C:16 CS:1210 Exam 2
April 5th, 6:30 pm to 8:30 pm
Instructions:
This is an open notes exam and you have 2 hours to complete it. There are 4 problems in
the exam and these appear on 8 pages.
Make sure that you do not have any electronic devices (laptop
22C:16 CS:1210 Exam 1
Feb 22nd, 6:30 pm to 8:30 pm
Instructions:
This is an open notes exam and you have 2 hours to complete it. There are 4 problems in
the exam and these appear on 7 pages.
Make sure that you do not have any electronic devices (laptops
22C:16 (CS:1210) Quiz 10
You have 20 minutes to complete this quiz.
1. Write down the output produced (via the print statement) when the function given below
is called as
generalMergeSort([5, 6, -2, 1, 9], 0, 4)
# The merge sort function; sorts the sublis
Quick Sort
MAY 1ST, 2013
Quick Sort: Review
def generalQuickSort(L, first, last):
# Base case: if first = last, then there is only one element in the
# slice that needs sorting. So there is nothing to do.
# Recursive case: if there are 2 or more elements
22C:16 Practice Problem Set 10
Morning Section: Complete before Tuesday, 4-30-2013
Evening Section: Complete before Monday, 4-29-2013
These practice problems are all on recursion.
1. This question is about the fibonacci function shown below.
def fibonacci
22C:16 (CS:1210) Quiz 9
You have 20 minutes to complete this quiz. This quiz depends on the searchWordNetwork
function that was part of the program playLaddersGame2.py. Code from this function appears
on the back of this page.
Consider the network of word
22C:16 (CS:1210) Quiz 9
You have 20 minutes to complete this quiz. This quiz depends on the searchWordNetwork
function that was part of the program playLaddersGame2.py. Code from this function appears
on the back of this page.
Consider the network of word
22C:16 (CS:1210) Quiz 9
You have 20 minutes to complete this quiz. This quiz depends on the searchWordNetwork
function that was part of the program playLaddersGame2.py. Code from this function appears
on the back of this page.
Consider the network of word
22C:16 (CS:1210) Quiz 7
You have 20 minutes to complete this quiz.
Evaluate each expression and write down its value. Assume that (i) concat is a function that
takes two parameters a and b and returns a+b, (ii) isLen2 is a function that takes a parameter
22C:16 (CS:1210) Quiz 5
You have 20 minutes to complete this quiz.
1. Consider the following function denition.
def test(a, b = 0, c = 2, d = "12"):
return str(a - c) + d + str(b)
For each of the function calls below, rst write down if the function call c
22C:16 (CS:1210) Quiz 5
You have 20 minutes to complete this quiz.
1. Consider the following function denition.
def test(a, b = 0, c = 20, d = "12"):
return str(b) + str(c) + d + a
For each of the function calls below, rst write down if the function call
22C:16 (CS:1210) Quiz 4
You have 20 minutes to complete this quiz.
1. Consider the following expressions. For each expression, rst determine whether the expression is well-formed or not. For each well-formed expression, determine if the expression
will be
22C:16 (CS:1210) Quiz 4
You have 20 minutes to complete this quiz.
1. Consider the following expressions. For each expression, rst determine whether the expression is well-formed or not. For each well-formed expression, determine if the expression
will be
22C:16 (CS:1210) Quiz 3
You have 20 minutes to complete this quiz.
1. Suppose that variable x has value 7 and variable y has value 8. Evaluate each of the
following boolean expressions.
(a) (x >= y) and (x < 0)
(b) (x < 8) and (8 > y)
(c) not(not(y % x) !
22C:16 (CS:1210) Quiz 3
You have 20 minutes to complete this quiz.
1. Suppose that variable x has value 11 and variable y has value 6. Evaluate each of the
following boolean expressions.
(a) (x/y < 2) and (x > 0)
(b) (x > 8) and (8 < y)
(c) not(not(x % y)