CSE102 Exam 2 Sample Questions PDF
Document Details
Tags
Summary
This document contains sample programming questions for an exam. It includes multiple-choice and short answer questions on Python programming, focusing on data structures (lists, strings) and loops. Practicing these questions helps refine programming skills.
Full Transcript
Exam 2 Sample questions The questions below are similar to the types of questions you will see on the second exam. Answers for these questions can be found at the end of this document. Attempt these questions on your own, discuss your answers with your peers, and bring any remaining questions to yo...
Exam 2 Sample questions The questions below are similar to the types of questions you will see on the second exam. Answers for these questions can be found at the end of this document. Attempt these questions on your own, discuss your answers with your peers, and bring any remaining questions to your teaching assistants during the class period before the exam. Note that this list is not comprehensive, it is only intended to give you an idea of what the questions may look like. Other topics not represented on this list of sample questions may still be on the exam. In other words, do not use this document as your sole source of study material. 1. Strings – What is the result from the following code? a. 0 b. 3 c. 4 d. 5 2. For loops – How does the execution of a nested for loop work? a. The outer loop goes through one iteration for every time the inner loop runs through all of its iterations b. The inner loop goes through one iteration for every time the outer loop runs through all of its iterations c. The outer loop goes through all of its iterations while the inner loop goes through all of its own iterations d. The inner loop takes precedence and will stop the outer loop from going to anymore iterations even after the inner loop has finished. 3. Lists – What is the result from the following code? a. 0 b. 3 c. 4 d. 5 4. For loops – What numbers are generated from range(3, 11, 2)? a. 3, 5, 7, 9 b. 3, 3, 5, 5, 7, 7, 9, 9, 11, 11 c. 3, 5, 7, 9, 11 d. 3, 3, 5, 5, 7, 7, 9, 9 5. Strings – Which of the following methods is used to convert a string to be all lowercase? a. lowercase() b. islower() c. convertLow() d. lower() 6. Lists – Which of the below statements are true? a. Lists are a collection of data. b. Lists can store different types of data at the same time. c. Lists are ordered upon creation and the data will stay in that order unless modified by specific code. d. All of the Above 7. Lists – What is printed from the following code? a. Error: List Index out of Range b. ‘f’ c. ‘g’ d. ‘c’ 8. Strings – What is printed from the following code? a. $3.67. b. $3.679. c. $3.70. d. $3.68. 9. For loops –What is stored in the list nums after the following code is run? a. [13, 18, 15, 12, 9, 5] b. The variable nums no longer exists c. [7, 12, 9, 6, 3, -1] d. [10, 15, 12, 9, 6, 2] 10. Lists – Of the following methods, which sorts the list in reverse order? a. sort() b. reverse() c. sort(reverse=True) d. reversesort() 11. Strings vs Lists – Which of the following answers is True in regards to Python Lists and Strings? a. Both lists and strings are mutable. b. Lists are mutable and strings are immutable. c. Strings are mutable and lists are immutable. d. Both lists and strings are immutable. 12. For loops - In the following code, how many times is “Hello” printed? a. 7 b. 5 c. 10 d. 2 13. Strings – Which option below is equivalent to the following code? a. b. c. d. 14. For loop (vs while loop) - Which for loop below is equivalent to the following while loop? a. b. c. d. 15. Lists – What is stored in the variable candiesList from the code below: a. ["Skittles", "Butterfinger", "Sour Patch Kids", "M&M’s", "Milky Way"] b. ["Skittles", "Butterfinger", "Sour", "Patch", "Kids", "M&M’s", "Milky", "Way"] c. "Skittles Butterfinger Sour Patch Kids M&M's Milky Way" d. ["Skittles Butterfinger Sour Patch Kids M&M's Milky Way"] Answers: 1. c 2. a 3. a 4. a 5. d 6. d 7. a 8. d 9. d 10. c 11. b 12. c 13. c 14. b 15. b