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?
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?
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?
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
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?
Signup and view all the answers
Which statement accurately describes what a dictionary is in programming?
Which statement accurately describes what a dictionary is in programming?
Signup and view all the answers
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.
Signup and view all the answers
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?
Signup and view all the answers
What type of structure is a dictionary in programming?
What type of structure is a dictionary in programming?
Signup and view all the answers
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 odd -
wolvy
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.