CP104: Midterm Notes - Fall 2025

General Comments

The following are comments on the midterm. Please review this material before bringing any questions about your midterm to the instructor. You should also try completing your solutions in Eclipse for practice.

Submissions to the temp Dropbox

We allowed, and graded, zipped project submissions to the temp dropbox after the midterm dropbox closed because of wi-fi issues, problems with MLS, etc. This information was part of the emailed midterm instructions sent to all students before the midterm:

If you miss the deadline, submit your zipped project to the ‘temp’ dropbox as soon as possible. Note that only modules timestamped before the end of the midterm are graded.

This was not, however, an opportunity to continue working on code. Individual PyDev modules in the submitted zip files are time-stamped. So long as the module's time-stamp was before the midterm due time the code would be graded normally. Code updated a significant amount of time after the due time was not graded.

Empty Midterms

There are, alas, submissions to the dropboxes of empty midterms, i.e. the original projects we provided you without any code written into them. Naming the zip file badzip, the instructions to delete the original zip file after importing the project, and the validator rejecting the badzip name should be sufficient to avoid this problem. From the midterm instructions:

Delete the file badzip.zip. If this causes problems with your workspace, you imported the project in the zip file incorrectly. Re-download the file and try again. (Deleting this file avoids students submitting their original, empty, project as their midterm. This is a Bad Idea.)

And from the email Midterm Instructions sent to the class:

In Particular, Make Sure You Delete the BadZip Midterm zip file after you finish importing your customized midterm project from it. This zip file is named ‘badzip’ for a reason. A distressingly large (i.e. greater than zero) number of students end up submitting the empty zip file as their midterm submission every term. Don’t be one of these students.

Unfortunately not everyone followed the instructions. If you did this we will move your midterm grade to the final exam with a deduction of 2% in your final course grade.

Other Issues

Illness, absence, emergencies, etc., are dealt with on an individual basis.

Extra Marks

There were 40 graded marks on the midterm. However, the grade is recorded as out of 36. This means that that your grade was increased from its default, and that you could get greater than 100% on the midterm.

Get the project naming and organization correct!

A small minority of projects were misnamed, or contained multiple projects, or had comments and code removed that should not have been touched. The midterm was specifically set up to work like labs and assignments so as to be familiar to you, the only difference being the importing of the base project. The exam will be done the same way, so Get It Right if you are still struggling with this. Attend a lab for help, do the practice importing provided, import sample assignment answers for practice, use the same exporting procedures you normally use for exporting labs and assignments - assuming you do it correctly!

Remember basic CP104 rules:
  • get basic syntax correct - your code must execute properly. Eclipse often warns you when there is a problem, pay attention!
  • only one return statement per function/method
  • do not use break, continue, or pass
  • do not name your variables the same as the function/method name

Read and apply method and function docstrings carefully:

Get the number and types of parameters correct, and the number and types of returned values correct. There is a major difference between print and return - you have to demonstrate that you understand this. Make sure the units are correct - cents vs dollars, for example.

Use function parameters properly

If you've written code like:


def some_rating(rating):
    """
    Use: level = some_rating(rating)
    -------------------------------------------------------
    Parameters:
        rating - some rating of a thing (int >= 0)
    """
    rating = int(input("Enter rating: "))
    …

      

then you are missing one of the fundamental concepts of a function. In this example, rating is passed into the function from the program that calls the function - do not ask for, or set, the parameter value inside the function. Yes, there are functions that do ask the user to enter values, but the docstring tells you when to do that. The docstring here, in both the Use: and Parameters section, make it clear that rating is to be passed into the function when called, not asked for inside the function.

On the other hand, if the function documentation specifically asks for the user to input values, then ask the user. Always pay close attention to the documentation.

Requirements

Every task had a list of bullet-point Requirements listed. To get full marks on any Task you must follow the Requirements as listed. In some cases not following a Requirement gives a 0 on the entire task. From the midterm instructions:

Where Requirements are listed, make sure you meet them. For example, if a function is required to use a fallthrough algorithm, and your code does not, you will not get full marks.

Meeting the Requirements is non-negotiable.

Named Constants

You needed to demonstrate that you understand the use of named upper-case constants. ( See Constants.) The key words here are:

  • named: a value is given a name in the same way a variable is given a name
  • upper-case: the name must be in all upper-case to visually distinguish it from variables
  • constant: the value should be assigned once and never changed, and these values should be simple integers or floats, not code like int(10)

and then this constant is used in the place of value in the code.

Further the constants should represent the value named. Thus:

          
DISCOUNT = 10
DISCOUNT = 0.10
        

are not the same as, and do not have the same meaning as:

          
DISCOUNT = 0.9
        

The latter tells you the result of applying the discount, not what the discount actually is. To get the constant mark you must use proper constants that match the meanings discussed in the Task and function documentation.

Better code gets better marks. Missed the constants marks? You can still get the testing marks.

Final Comments

'open book' does not mean 'easy', it simply gives you access to all of the material you have been working with during the term. The amount of time required to look through existing code or Googling it on Stack Overflow is costly. Having practiced writing code so that it immediately comes to mind is a much better, less time-wasting approach.

Do not ask us "for just a few marks so I can pass the midterm". You don't have to pass the midterm to pass the course. We don't hand out free marks just to make a certain grade level. If you did poorly on the midterm, you have an opportunity to improve for the exam, assuming you stay in the course. You must, however, pass the final exam to pass the course. No Exceptions For Any Reason.

If you passed the midterm remember that a bare pass is not going to get you into 2nd year. You need to demonstrate mastery of this material, and 52% isn't really doing that.

We do not provide the complete code for the answers. Go through the midterm again on your own and attempt to complete and test it thoroughly as good practice.


The Tasks

Task 1

This Task tested both your understanding of constant defining and usage as well as simple math with modulus and integer division. You could still get partial marks with returning the correct values even by using more complex techniques.

Task 2

This Task specifically asked for the use of a fallthrough algorithm. See the notes entitled Fallthrough Algorithms. You could certainly still get significant part marks on this function by returning (not printing) the proper values, but for full marks the function must use a fallthrough algorithm. A fallthrough if structure for these functions has:

  • A single if - elif - else structure
  • only simple comparisons - no Boolean and or or complex comparisons
    (e.g. x > 300 and x < 1000)
    or their equivalent
    (e.g. x < y < z).
Task 3

The point of these functions was to test your understanding and skills with nested if structures. You needed to demonstrate that you understood that only if a specific condition was met was there a need to ask the user for further input, than then had another if applied to it. If that original condition was not met, then the function was done.

As an example, if a certain purchase level had to be met before a membership bonus kicked in, it is pointless to have this conversation with the user:

"How many items do you want?"
"One."
"Are you a member?"
"Yes."
"Oh well, your membership status doesn't matter because you didn't buy enough stuff."

That's just annoying from a user interface point of view. (We've worked through such examples in the notes and labs.)

Note that the two samples given on the midterm were specifically chosen to demonstrate this: one ask for the membership status, the other did not.

Task 4

This task tested your mastery of formatted printing as well as returning the a correct value. Using f-string formatting codes to create proper table alignments was key to getting full marks on this Task.

Task 5

You were to write testing code for a given function. If nothing else, you could have literally copy/pasted and edited any of the testing code we gave you for the other Tasks.

We expected your code to:

  • import the function to be tested. The import code given for the other testing tasks, t0.py through t04.py were a good guide for how this is done.
  • ask the user for a testing value. Give a prompt and read the proper type of value.
  • call the function and assign the returned value to a variable.
  • print the result variable. If you don't print the result, how can you know if it worked?

You should be doing this for all labs and assignments rather than just letting the online testing take care of this for you. Knowing how to execute your own code is important!