{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

test1spring11

test1spring11 - Test 1 Compsci 06 Owen Astrachan Name...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
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 . Don’t worry about getting function or method names exactly right. Assume that all libraries and packages we’ve discussed are imported in any code you write. 1
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 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 .
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern