Exam 3 Sample Questions PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document contains sample programming questions, covering topics such as functions, files, and dictionaries. The questions are designed to prepare students for an exam assessing their understanding of these fundamental concepts.
Full Transcript
Exam 3 Sample questions The questions below are similar to the types of questions you will see on the third 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 the...
Exam 3 Sample questions The questions below are similar to the types of questions you will see on the third 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 the instructors through Piazza or office hours. Your teaching assistants can also help you with these problems. 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. Function Call – What is the value returned from the function call on line 12? a. 3 b. 2 c. 4 d. An error will occur as x, y and z are not defined. 2. Return values – Considering the function definition below, which function calls will produce a return value of 10? a. mystery(4,3,6) b. mystery(3,7,4) c. mystery(10,1,0) d. mystery(1,8,2) e. mystery(5,5,5) 3. Files – Which of the following lines of code will open a file, ‘test_answers.txt’ for reading only? a. fn = open(“test_answers.txt”, ‘read’) b. fn = open(“test_answers.txt”, ‘r’) c. fn = open(“test_answers.txt”, ‘a’) d. fn = “test_answers.txt”.open() 4. Files – What does the next() function do in terms of reading from a file? a. The next function jumps to the next file in the directory to be read. b. The next function moves to the next page in the file. c. The next function allows lines in the file to be skipped. This is very useful for skipping the header row in CSV files. d. The next function skips to the next character in the file. 5. Dictionaries – What is a dictionary? a. Dictionaries are just a list with a different name b. Dictionaries are a data structure that can store information using strings only. c. Dictionaries are a data structure similar to lists that can store information in key-value pairs. d. Dictionaries are a data structure similar to lists that can store information in key-value pairs however they are immutable after creation. 6. Tracing Code – What is the outcome of executing the following code segment? a. Go white! Go green! Go white! Go green! Boo blue! Boo blue! Boo blue! Boo blue! b. Boo blue! Go white! Go green! Go white! Go green! c. Boo blue! Go green! Go white! Go green! Go white! d. Go green! Go white! Go green! Go white! Boo blue! Boo blue! Boo blue! Boo blue! 7. CSV Unpacking – You are reading in a csv file, data.csv, that has 3 columns. Name, Age and Email. What is the issue with the code below? a. There is nothing wrong with the above code b. The csv reader object is not being created properly and will cause an error. c. The csv file is not being opened properly and will cause an error. d. The data from the csv reader is not being unpacked properly and will cause an error. 8. File Data – What type is the data read in as from a csv file when using the csv reader object? (Not the entire row, but one entry in the row) a. String b. Float c. Integer d. Depends on the data being read in. If it is a number, it will be a float or integer. Otherwise, it is a string. 9. Dictionaries – What dictionary method is used to iterate over both keys and values? a. keys() b. items() c. values() d. pairs() 10. Function terms – Which term is used for values passed into a function when it is called? a. Arguments b. Parameters c. Variables d. Inputs 11. Dictionaries – What data type cannot be used as a key in a dictionary? a. Integer b. Float c. Bool d. List 12. Functions – What is the output from the following code? a. The function has opened The function is closing Checkpoint 2 b. The function has opened Checkpoint 2 The function is closing c. The function has opened Checkpoint 1 d. Checkpoint 2 The function has opened The function is closing 13. Dictionaries – Of the following options, which one(s) allow you to iterate through all of the keys in a dictionary? a. b. c. d. 14. Files – When writing to a txt file, what type must the value you are writing be? a. The type does not matter. b. Integer, Float or String c. Integer or String d. String 15. Dictionaries – Based on the following dictionary: which option(s) update the values stored in the dictionary for each key? a. b. c. d. Answer Key 1. b 2. a, b & e 3. b 4. c 5. c 6. d 7. d 8. a 9. b 10. a 11. d 12. C 13. a & c 14. d 15. b & d