This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CompSci 6 Test 1 Fall 2011 PROBLEM 1 : ( What is the output? (10 points) ) A. (5 pts) What is the output of the following code segment? Write the output to the right. Note that there is only output for the print statements. Output: x = 5 y = 3.0 print 2 + x * 4 print x * 4 + 2 print 12 / x print 10 / y print x > 2 B. (5 pts) What is the output of the following code segment? Write the output to the right. Note that there is only output for the print statements. Output: sport = "cross country" print sport print sport[2:4] print sport[sport.find(t):] spices = [basil, dill, chickory, parsley, sage] print spices print spices[2:4] PROBLEM 2 : ( Triangles and Dinner - Simple Functions (14 points) ) A. (6 pts) An equilateral triangle has all three sides of the same length. The area of an equilateral triangle with a the length of a side is 3 4 * a 2 . Write the function areaEquilateralTriangle that has one float parameter side represent- ing one side of an equilateral triangle and returns the area of the triangle. 1 call returns areaEquilateralTriangle(4.2) 7.63834406138 areaEquilateralTriangle(2.0) 1.73205080757 areaEquilateralTriangle(1.5) 0.974278579257 def areaEquilateralTriangle(side): given one float parameter side representing the length of one of the sides, returns a float that is the area of the equilateral triangle B. (8 pts) Ellen and Oscar want an easy way to decide who will cook dinner each night....
View Full Document
This document was uploaded on 01/17/2012.
- Fall '09