test1fall10

# test1fall10 - Test 1: Compsci 06 Owen Astrachan October 6,...

This preview shows pages 1–6. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document
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 October 6, 2010 Name: NetID/Login: Honor code acknowledgment (signature) value grade Problem 1 12 pts. Problem 2 24 pts. Problem 3 16 pts. Problem 4 15 pts. TOTAL: 67 pts. This test has 13 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 . 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 : ( Outside (12 points) ) The Python code below generates six lines of output. Write each line of output after the print statement that generates it. num = 13 d = 7.5 s = &amp;quot;please&amp;quot; print num/2 print s[1:] print s[3] print num % 5 print s*2 print (num-11)**3 2 PROBLEM 2 : ( Tis a Gift to be Simple (24 points) ) Part A Write the function sphereV that returns the volume of a sphere whose radius is given by the parameter r . The formula for the volume of a sphere is 4 3 r 3 You can use either 3.1415 or math.pi for . call return value sphereV(1) 4.1887902 sphereV(2) 33.510321 def sphereV(r): &amp;quot;&amp;quot;&amp;quot; returns volume of sphere whose radius is given by float r &amp;quot;&amp;quot;&amp;quot; 3 Part B Recall that the Python expression &amp;quot;at&amp;quot;*3 evaluates to the string &amp;quot;atatat&amp;quot; and the expression &amp;quot;++&amp;quot;*4 is the String &amp;quot;++++++++&amp;quot; . Write the function pyramid that prints a pyramid whose number of levels is given by parameter levels . The function prints a pyramid, it doesnt return any value. The figure on the left below is generated by pyramid(5) and the figure on the right is generated by by pyramid(3) . * * ** ** *** *** **** ***** In general there are n asterisks on level n . def pyramid(levels): &amp;quot;&amp;quot;&amp;quot; print a pyramid with the number of levels specified &amp;quot;&amp;quot;&amp;quot; 4 Part C Write the function lastFirst described below that returns a String in the format first last given a String in the format last, first as shown in the examples. call return value lastFirst(&amp;quot;Smith, John&amp;quot;) &amp;quot;John Smith&amp;quot; lastFirst(&amp;quot;Van Doren, Mamie&amp;quot;) &amp;quot;Mamie Van Doren&amp;quot; lastFirst(&amp;quot;Begley Jr., Ed&amp;quot;) &amp;quot;Ed Begley Jr.&amp;quot; The String parameter name passed to lastFirst will alway contain a String in the format last, first...
View Full Document

## This document was uploaded on 01/17/2012.

### Page1 / 13

test1fall10 - Test 1: Compsci 06 Owen Astrachan October 6,...

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

View Full Document
Ask a homework question - tutors are online