0% found this document useful (0 votes)
18 views

Sample Test 2b

This document contains a practice test for a computer science course. It has 17 multiple choice and code writing questions covering topics like functions, loops, arrays, and string formatting. The test asks the student to write code for tasks like printing numbers in a range, calling functions, summing arrays, and comparing output of nested loops. It also contains questions to test understanding of function parameters and returns, string concatenation, and integer conversion.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Sample Test 2b

This document contains a practice test for a computer science course. It has 17 multiple choice and code writing questions covering topics like functions, loops, arrays, and string formatting. The test asks the student to write code for tasks like printing numbers in a range, calling functions, summing arrays, and comparing output of nested loops. It also contains questions to test understanding of function parameters and returns, string concatenation, and integer conversion.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CmSc 150, Fall 2012 Test 2 Test 2

Name: _________________________

Section:_________________________

1. (1 pt) What was the point of showing the Excel chart demonstration in class?

2. (2 pts) Write a while loop that prints the numbers starting at 500 down to 100. Count down by
10’s. Make sure to print both the numbers 500 and 100.

3. (2 pts) Write a function that prints the name of your favorite liquid beverage.

4. (1 pt) Write code that calls the function in the prior problem.
CmSc 150, Fall 2012 Test 2 Test 2

5. (3 pts) Write a function that will take in three numbers, and return how many are the same. For
example, passing in 5, 5, and 5 should return a three. Passing in 5, 4, 4 should return 2. And
passing in 3, 4, 5 would return 0.

6. (2 pts) Write code that will call the function in the prior problem and print the result. Make up
the numbers that are passed in.

7. (3 pts) What does this code print?

def b():
print ("b start")
c()
print ("b end")

def a():
print ("a start")
c()
b()
print ("a end")

def c():
print ("c")

a()
CmSc 150, Fall 2012 Test 2 Test 2

8. (2 pts) What does this code print?

def a(x):
print("A1",x)
x=x+5
print("A2",x)
return x

def b(x):
print("B1",x)
a(x)
print("B2",x)

x=5
print("G1",x)
b(x)
print("G2",x)

9. (1 pt) What is the value of x?

def sum(a,b):

print (a+b)

x = sum(11,22)

10. (3 pts) Write a function that will take in an array, and print each element individually:
CmSc 150, Fall 2012 Test 2 Test 2

11. (5 pts) Write a function that will take in an array, and return the sum.

12. (3 pts) Take a look at the two blocks of code below. Explain or write out how their output will be
different:

# Block 1
for i in range(3):
for j in range(3):
print ("*",end="")
print ()

# Block 2
for i in range(3):
for j in range(3):
print ("*",end="")
print ()
CmSc 150, Fall 2012 Test 2 Test 2

13. (1 pt) What does this code print?

x=[[3,[4,5]],6,7,8,[9,10]]

print (len(x))

14. (4 pts) This code should count the number of times a number appears in an array, in this case 2.
There are 5 things wrong with this code. Find at least 4:

def countNumbers(list,key):

count=0

for i in range( list ):

if list == key:

count += 1

return count

myList=[3,4,32,4,23,4,5,3,2,2,43,56,7,54,43,2,4]

c=countNumbers(list,2)

print(count)
CmSc 150, Fall 2012 Test 2 Test 2

15. (2 pts) What two things are wrong with this code? Explain.

def printCircleAreaChart(start,end):
for r in range(start, end):

def circleArea(radius):
area=3.14159*radius**2
print (area)

area = circleArea(r)
print (r, area)

printCircleAreaChart(10,30)

16. What would this code snippet print to the screen?

print("A\\\\B\nC\"D")

17. What would the following code print?

print ("00"+"11")

print (00+11)

You might also like