Exam 2- 2011

F printf1 g x 300 y0 printf2y

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

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

{[ snackBarMessage ]}

What students are saying

• 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.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern