test1spring11

test1spring11 - Test 1: Compsci 06 Owen Astrachan February...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Test 1: Compsci 06 Owen Astrachan February 23, 2011 Name: NetID/Login: Honor code acknowledgment (signature) value grade Problem 1 27 pts. Problem 2 20 pts. Problem 3 16 pts. Problem 4 12 pts. TOTAL: 75 pts. This test has 10 pages, be sure your test has them all. Do NOT spend too much time on one question remember that this class lasts 75 minutes. In writing code you do not need to worry about specifying the proper import statements . Dont worry about getting function or method names exactly right. Assume that all libraries and packages weve discussed are imported in any code you write. 1 PROBLEM 1 : ( Stereo, Geno, and Proto (27 points) ) Part A (22 points) Each of the variables below has a type and a value . The type is one of: list, boolean, int, string, float. For example, consider the assignment to variable x below: x = len([1,2,3,4,5]) The type and value are shown in the first row of the table below. Fill in the other type and value entries based on the variable/expression in the first column. variable/expression type value x = len([1,2,3,4,5]) int or integer 5 a = 35/9 b = "concatenate"[3:6] c = "one two three".split() d = 32 < 6 e = sum(range(0,5)) f = 4.0*2.5 g = "apple" + "pie" h = 37 % 6 i = "tortoise"[2] j = 4**3 k = [2,3,5,7,11,13,15][2:4] (continued) 2 Part B (2 points) In the python code shown below an assignment is made to b[0] (the value tiny is assigned to b[0] ) and as shown the value of a[0] changes as well. In a sentence or two explain why the value of the list a changes when the assignment is to b[0] . >>> a = [big, small, medium, tired] >>> b = a >>> a [big, small, medium, tired] >>> b [big, small, medium, tired] >>> b[0] = tiny >>> b [tiny, small, medium, tired] >>> a [tiny, small, medium, tired] >>> Part C (3 points) The average word length of the words in the list words = ["dog", "cat", "eagle", "vulture", "lion", "salamander"] is 5.333. Complete function avglen below so that the expression avglen(words) evaluates to 5.333 by adding to the one missing line that uses a list comprehension. Complete the missing line by filling in the list comprehension so that the function returns the average length of the strings in parameter words . You should only modify the line that assigns a value to num . def avglen(words): """ words is a list of strings, returns average length of strings """ denom = float(len(words)) if denom == 0.0: return denom num = sum([ for w in words]) return num/denom 3 PROBLEM 2 : ( Disfunctional, Malfunctioning, Perfunctory (20 points) ) Part A (5 points) Write the function cone_volume that returns the volume of a cone whose radius is given by the parameter r and whose height is given by the parameter...
View Full Document

This document was uploaded on 01/17/2012.

Page1 / 10

test1spring11 - Test 1: Compsci 06 Owen Astrachan February...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online