Podcast
Questions and Answers
What problem might arise with the code if the csv reader object is not created properly?
What problem might arise with the code if the csv reader object is not created properly?
- The data from the csv reader is not being unpacked properly and will cause an error.
- The csv reader object is not being created properly and will cause an error. (correct)
- There is nothing wrong with the code.
- The csv file is not being opened properly and will cause an error.
When using the csv reader object, what data type is typically read for one entry in the row?
When using the csv reader object, what data type is typically read for one entry in the row?
- Float
- Depends on the data being read in. (correct)
- Integer
- String
What dictionary method allows you to access both keys and values in a dictionary simultaneously?
What dictionary method allows you to access both keys and values in a dictionary simultaneously?
- values()
- keys()
- items() (correct)
- pairs()
Which of the following cannot be used as a key in a dictionary?
Which of the following cannot be used as a key in a dictionary?
What is the correct term for values passed into a function during its call?
What is the correct term for values passed into a function during its call?
What method correctly allows you to iterate through all keys in a dictionary?
What method correctly allows you to iterate through all keys in a dictionary?
When writing to a text file, what type must the value you are writing be?
When writing to a text file, what type must the value you are writing be?
Which of the following options can be used to update values in a dictionary?
Which of the following options can be used to update values in a dictionary?
What value will be returned from the function call on line 12 if the function is defined to return 3?
What value will be returned from the function call on line 12 if the function is defined to return 3?
Which of the following function calls will produce a return value of 10 based on its definition?
Which of the following function calls will produce a return value of 10 based on its definition?
Which line of code correctly opens a file 'test_answers.txt' for reading only?
Which line of code correctly opens a file 'test_answers.txt' for reading only?
What is the primary function of the next() function when reading from a file?
What is the primary function of the next() function when reading from a file?
Which statement accurately describes what a dictionary is in programming?
Which statement accurately describes what a dictionary is in programming?
What will be the output of the following code segment that prints colors? Assuming the print function is called correctly.
What will be the output of the following code segment that prints colors? Assuming the print function is called correctly.
Which line does NOT correctly utilize the open function to access a file?
Which line does NOT correctly utilize the open function to access a file?
What type of structure is a dictionary in programming?
What type of structure is a dictionary in programming?
Flashcards
Function Call (Line 12)
Function Call (Line 12)
Evaluating a function with supplied inputs. It calculates a value based on the input.
Return Value of 10 (mystery function)
Return Value of 10 (mystery function)
Specific input values to the function mystery
resulting in the function returning 10.
Opening a file ('test_answers.txt')
Opening a file ('test_answers.txt')
Reading data from the file 'test_answers.txt'.
next() function (file reading)
next() function (file reading)
Signup and view all the flashcards
Dictionaries
Dictionaries
Signup and view all the flashcards
Tracing Code
Tracing Code
Signup and view all the flashcards
Function definition in Python
Function definition in Python
Signup and view all the flashcards
File modes (Python)
File modes (Python)
Signup and view all the flashcards
CSV Unpacking Issue
CSV Unpacking Issue
Signup and view all the flashcards
CSV Data Type
CSV Data Type
Signup and view all the flashcards
Dictionary Iteration (Keys & Values)
Dictionary Iteration (Keys & Values)
Signup and view all the flashcards
Function Arguments
Function Arguments
Signup and view all the flashcards
Dictionary Non-Key Type
Dictionary Non-Key Type
Signup and view all the flashcards
Function Output (Example)
Function Output (Example)
Signup and view all the flashcards
Dictionary Key Iteration
Dictionary Key Iteration
Signup and view all the flashcards
File Write Data Type
File Write Data Type
Signup and view all the flashcards
Study Notes
Exam 3 Sample Questions
- Sample questions similar to those on the exam are provided.
- These questions are not exhaustive, and other topics may appear on the exam.
- Use this document as supplemental study material.
Question 1: Function Call
- Problem: Determine the returned value from a function call.
- Function:
mystery(x, y, z)
- Takes three arguments
x
,y
, andz
- If
x > 0
, then:- If
y < z
, returnx
- Otherwise, return
y + z
- If
- Otherwise, return
y
- Takes three arguments
- Values:
a = 3
,b = 4
,c = -2
- Call:
mystery(a, b, c)
- Solution: The code returns 3 because
a
is 3,a > 0
is true, andb
is 4, andc
is -2, and4 > -2
is true, soa = 3
is returned from the function
Question 2: Return Values
- Problem: Identify function calls that return a value of 10.
- Function:
mystery(a, b, c)
- If
a > b
, then:- If
b < c
, returna + c
- Otherwise, return
b + c
- If
- Otherwise, return
a + b
- If
Question 3: Files
- Problem: Identify the correct code for opening a file for reading only.
- Solution:
fn = open("test_answers.txt", 'r')
Question 4: Files – next() Function
- Problem: Describe the function of the
next()
function in file reading. - Solution: The
next()
function skips to the next line in the file, useful for skipping headers.
Question 5: Dictionaries
- Problem: Define a dictionary.
- Solution: A dictionary stores data in key-value pairs.
Question 6: Tracing Code
- Problem: Determine the output from a given code segment.
- Code: Defines functions
sparty
andwolvy
sparty
prints "Go green!" if its input (n
) is even, and "Go white!" if oddwolvy
returns its input multiplied by "Boo blue"- Code loops for 5 iterations
- Output: The output shows a repeating pattern of "Go white!" and "Go green!" interspersed with "Boo blue"
Question 7: CSV Unpacking
- Problem: Identify the issue within a CSV file reading program.
- Solution: The data from the CSV reader isn't unpacked correctly.
Question 8: File Data
- Problem: Determine the type of the data read from a CSV file using
csv.reader()
. - Solution: The data type is dependent on the data. Numbers are floats or integers, otherwise they're strings
Question 9: Dictionaries – Method for Iteration
- Problem: Identify the dictionary method used for iterating over both keys and values.
- Solution:
items()
Question 10: Function Terms
- Problem: Identify the term for values passed into a function.
- Solution: Arguments
Question 11: Dictionaries – Invalid Keys
- Problem: Determine which data type cannot be used as a key in a dictionary.
- Solution: Lists
Question 12: Functions – Output
- Problem: Determine the output from a given function.
- Solution: The function prints messages about opening and closing, and it returns the value assigned to the variable "check" within the function.
Question 13: Dictionaries – Key Iteration
- Problem: Identify options for iterating through dictionary keys.
- Methods:
dictionary.keys()
,for key in dictionary:
Question 14: Files – Data Type
- Problem: Determine the required data type for writing to a text file.
- Solution: String
Question 15: Dictionaries – Value Update
- Problem: Identify options that update the values in a dictionary.
- Solution: Iterating over the keys (
dictionary.keys()
) and updating the values using the key as index, for exampledictionary[‘key’] = {value}
.
Answer Key
- Numerical answers to the corresponding question are provided.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your understanding of function calls and return values with this exam sample. The questions focus on conditional logic in function definitions and help you prepare for your upcoming exam. Use this supplement as a part of your study strategy.