Exam 2- 2011

F printf1 g x 300 y0 printf2y

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: en defined: def f1( ): return 8 def f2(x): return 5 + x def f3(L): return (len(L)) def f4(x): y=x x = 12 return y ** 2 What will the following snippets of code print? (f) print(f1()) (g) x = 300 y=0 print(f2(y)) (h) a = [5, 4, 3, 2, 1,0] print(f3(a)) CS 115 Exam 2, Fall 2011 Page 4 of 9 (i) x=4 print(f4(x)) print(x) (j) print(f2(f2(0))) CS 115 Exam 2, Fall 2011 Page 5 of 9 Problem 2: 30 points. Write functions to perform the following tasks. Keep in mind the following: • Your functions should NOT ask the user for input. • Your functions should NOT print anything. • Your functions should NOT call sys.exit() to terminate the program. (a) Write a function called convert_dollars that… * has one input parameter: a price in cents * returns the corresponding price in dollars (b) Write a function called find_candy that… * Takes 2 strings as input parameters * Returns the string "delicious" if at least one of the strings is "candy" *If neither of the string is "candy", returns the string &qu...
View Full Document

This note was uploaded on 02/08/2014 for the course CS 115 taught by Professor Staff during the Fall '08 term at Sonoma.

Ask a homework question - tutors are online