test1fall10

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

Info iconThis preview shows pages 1–6. 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

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 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 = "please" 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): """ returns volume of sphere whose radius is given by float r """ 3 Part B Recall that the Python expression "at"*3 evaluates to the string "atatat" and the expression "++"*4 is the String "++++++++" . 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): """ print a pyramid with the number of levels specified """ 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("Smith, John") "John Smith" lastFirst("Van Doren, Mamie") "Mamie Van Doren" lastFirst("Begley Jr., Ed") "Ed Begley Jr." 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 Right Arrow Icon
Ask a homework question - tutors are online