Additional Help

On this page you can find additional hints and help for if you get stuck on the lab. We encourage you to use this information only after giving the problem a few minutes of thought on your own.





Table of Contents
  1. Are you stuck on how to get started?
  2. Still don't know how to get started?
  3. Not sure how to remove courses from the list?
  4. Still having trouble removing courses from the list? or Is your loop behaving in a way you don't expect?
  5. Are you getting a "TypeError" message?
  6. Having trouble keeping track of the grades as you remove courses?
  7. Getting a "ZeroDivisionError" error, or having trouble computing the average?



Are you stuck on how to get started?

Take a minute to read the code that was given to you, and make sure you understand the overall plan of the program before you dive right in. The comments should give a good overview, even though much of the code is missing.

(back to top)
































Still don't know how to get started?

Start by creating the sentinel loop that gets the user to enter an item. Get the loop to work (stopping when the user enters "NONE") before you worry about anything else.

If you accidentally made an infinite loop, use CTRL+C to stop it running!

(back to top)
































Not sure how to remove courses from the list?

You will need to use a while loop. It should be used in conjunction with the .remove() function. If you're still stuck, make sure the conditional your while loop uses stops at the correct point.

(back to top)
































Still having trouble removing courses from the list?
or
Is your loop behaving in a way you don't expect?

The first step is to "walk through" your code line by line, pretending to be the computer. Make sure that your conditionals are checking what you actually intend, and that variables are updated as you expect. Trying it with some example input will often help you spot errors.

If you're still stuck, you can try using a "debug statement" or two. These are print() statements that give you a bit more information on what exactly is going on. For example, you might want to see if the items are actually being removed:
    print("The list is currently", len(courses), "items long.")

Or your might want to see how the list is changing:
    print("The list is:", courses)

If you place either of these print() statements inside the while loop where you are removing the items, it will show you what is going on in the "background" of your program. Each time the while loop is run, the information in your debug statement will be printed to the screen, allowing you to trace what happens with each iteration of the while loop.

Debug statements can be anything that helps you figure out what your program is actually doing. Just don't forget to remove them when you're done!

(back to top)
































Are you getting a "TypeError" message?

Unlike print(), input() only accepts a single string, which means you can't use commas to separate raw strings from variables. So if you want to include the sentinel variable in your user prompt without simply writing it in, you'll need to find some way to add together the strings you want in the input.

The example sentinel loop in the Pre Lab uses this method, meaning that if the sentinel value changes, we don't have to update our user prompt string manually.

(back to top)
































Having trouble keeping track of the grades as you remove courses?

You should use a variable to keep track of a "running total" — the variable should be initialized before the loop begins. After getting the grade for a course, you should remove it from the list. The loop should end when the list is empty.

If you accidentally made an infinite loop, use CTRL+C to stop it running!

(back to top)
































Getting a "ZeroDivisionError" error, or having trouble computing the average?

After your program removes all of the courses, the course list no longer has any information about how many courses the student took. You'll need to figure out a way to save that information before any courses are removed.

(back to top)