MTH 4300 Diagnostic Exam
This quiz assesses your readiness based on the Python programming course you completed. It covers core concepts that will be essential as we transition to C++. Answer all questions to the best of your ability. This is not graded, but it will help your instructor understand where to focus early instruction. You have 45 minutes.
Section 1: Code Tracing
For each question, predict the exact output the program would print.
Q1.
What does this program print? Write the output exactly as it would appear.
Q2.
What does this program print? Trace through each iteration.
Q3.
What does this program print?
Q4.
What does this program print? Pay close attention to what is modified and where.
Section 2: Short Written Answer
Answer in your own words. Complete sentences are encouraged.
Q5.
In your own words, what is a class? What is the difference between a class and an instance of a class? Give a real-world analogy to support your answer. Also: what does the self parameter represent in a Python method?
Section 3: Write a Function
Write working Python code. You may use any built-in data types, but the restrictions noted in each question apply.
Q6.
Write a function second_largest(nums) that takes a list of integers and returns the second largest value. Do not use Python's built-in sorted() or max(). Assume the list has at least two distinct values.
Section 4: Debugging
The function below contains a bug. Identify the bug and write a corrected version.
Q7.
The function below is supposed to remove all negative numbers from a list and return the result. It has a bug. Identify it and write the corrected version.
Describe the bug:
Corrected code: