test2fall10 - Test 2 Compsci 06 Owen Astrachan Robert...

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

View Full Document Right Arrow Icon
Test 2: Compsci 06 Owen Astrachan Robert Duvall November 17/18, 2010 Name: NetID/Login: Honor code acknowledgment (signature) value grade Problem 1 12 pts. Problem 2 6 pts. Problem 3 12 pts. Problem 4 8 pts. Problem 5 20 pts. Problem 6 10 pts. TOTAL: 68 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. The last page is blank, if you use it make a note for the problem. 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 iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
PROBLEM 1 : ( Exlax (12 points) ) Part A (4 points) Complete the list comprehension below to create a list from all the strings in the list compounds , a list of strings, that have fewer than six characters. [ for w in compounds ] Part B (4 points) Write a list comprehension that creates a list of all the multiples of 5 greater than 0 and less than 4096, e.g., [5,10,15,...,4095]. Part C (4 points) Write a list comprehension that creates a list of all the prime numbers less than 10,000. You can use the function prime below that returns True if and only if its parameter num is a prime number. def prime(num): if num == 2: return True if num % 2 == 0: return False limit = int(math.sqrt(num)) + 1 for n in range(3,limit): if num % n == 0: return False return True 2
Image of page 2
PROBLEM 2 : ( What’s the Point? (6 points) ) Write the function minDistance that returns the minimal distance between two points in a list of points where points are represented as tuples.
Image of page 3

Info iconThis 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