test2spring2011

test2spring2011 - Test 2: Compsci 06 Owen Astrachan April...

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

View Full Document Right Arrow Icon
Test 2: Compsci 06 Owen Astrachan April 13, 2011 Name: NetID/Login: Honor code acknowledgment (signature) value grade Problem 1 24 pts. Problem 2 22 pts. Problem 3 18 pts. Problem 4 10 pts. TOTAL: 74 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. You should spend roughly one minute per point. 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
PROBLEM 1 : ( Myrmecophagous? 24 points) Write Python statement(s)/expression(s) to solve each of the problems below. Consider the list lista below used to illustrate each problem. lista = ["sloth", "aardvark", "pangolin", "pangolin", \ "aardvark", "sloth", "sloth", "numbat","anteater"] This list is used to illustrate the problems, but the code you write should work with any values stored in lista , don’t write code that depends on any particular values stored in the list. Part A (4 points) Write Python code that stores in variable uniq the number of different values in lista — this is five in the example above since the five different strings in lista are ’sloth’, ’aardvark’, ’pangolin’, ’numbat’, ’anteater’. Part B (4 points) Write Python code that stores in variable smalls a list of of the strings in lista that have fewer than six letters in them. This would be ["sloth", "sloth", "sloth"] in the example above. The words in smalls should be in the same order they appear in lista . Part C (4 points) Write Python code that stores in variable most the number of times the most frequently occurring string in lista occurs — this is three in the example above (for "sloth" ). 2
Background image of page 2
Part D (12 points) Write Python code that stores in variable ordered a list of the unique strings in lista in order from most frequently occuring to least frequently occuring. Ties should be broken alphabetically, e.g., "aardvark" appears before "pangolin" in ordered below (using lista as above) because they both occur twice but "aardvark" comes before "pangolin" alphabetically. Using lista above the values stored in ordered are: ordered == ["sloth", "aardvark", "pangolin", "anteater", "numbat"] because the number of occurrences of each of these is 3, 2, 2, 1, and 1, respectively. Note that "anteater" is alphabetically before "numbat" and both occur one time. (You’ll earn more than half-credit if strings are ordered correctly by number of occurrences, but you don’t break ties alphabetically.) 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
PROBLEM 2 : ( Playing Dice With the Universe (22 points) ) Part A (3 points) This line appeared in the Hangman programs submitted by nearly every student where
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 01/17/2012.

Page1 / 10

test2spring2011 - Test 2: Compsci 06 Owen Astrachan April...

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