Cribsheet

This guide is designed to help you when you are struggling with your programming. Work through the stages and use this Wiki to help you locate and fix the problem.

  • The left-hand column is for “syntactic” problems – when your program is producing error messages.
  • The right-hand column is for “semantic” problems – when your program doesn’t do what you think it should, or when you have no idea where to start.

Got no program? Got no clue? Click here.

The program has errors

A. It has a syntax error

  1. What line is the error on?
    1. The problem is probably on this line.
    2. Also check the lines above and below
  2. Read the error message carefully.
    1. Have you seen this error before? What did you do then?
  3. Is it one of the common errors?
    1. Many errors are just spelling mistakes, missing colons, brackets or quotation marks
    2. Look at the error line and message carefully. Have you missed something?
  4. Compare to an example.
    1. Look at a similar line that you know works. What's the difference?
  5. In complex code, build it up gradually.
    1. Start with something simple and check it works.
    2. Build up your code a piece at a time - which addition causes the error to appear?
  6. Check your indentation.
    1. Have you indented each block to the right level?
    2. Have you mixed tabs and spaces?

B. The program runs, but with errors

  1. What line is the error on?
    1. The problem is probably on this line
    2. Also check the lines above and below
  2. Read the error message carefully.
    1. Have you seen this error before? What did you do then?
  3. Is it one of the common errors?
    1. Have you spelt each variable, function and keyword correctly? Remember: Python is case sensitive.
    2. Are you working with variables of appropriate type?
  4. Is this a problem with your programming environment?
    1. Make sure you run with IDLE so that you can see the error message.
    2. Did you open your .py file with right-click/Open with...?
    3. Obscure Tkinter or Canvas problems can sometimes be fixed by restarting IDLE.

The program does the wrong thing

It doesn't do what I expect

  1. Make sure you can see any error messages - run your program through IDLE.

C. General advice

  1. What do you want your program to do?
    1. Write a plan. What should the code be doing at each stage in the plan?
    2. What data are you storing? Should you be using lists? Strings?
    3. Look at "I don't know where to start" below.
  2. What does your program actually do?
    1. Execute your code by hand - does it do what you wanted it to do?
    2. Add some test output statements - what are the values of variables at various points in the code?
    3. Create a small test file and put bits of your code in there. Make sure each piece works before you integrate it back into your main program.

Specific advice

  1. While loops and if statements:
    1. What variables do you use in the condition? When do these variables change? What will the value of the condition be as the program runs?
  2. Functions:
    1. What parameters does the function have? What does it return? Are you using the right types? In the right order?

D. I don't know where to start

  1. Read the assignment carefully
    1. Follow each instruction step by step
    2. Read any material or exercises it refers to.
  2. Is this like a problem you've seen before?
    1. How is it similar? How is it different?
    2. Copy the similar pieces into a new file and modify them to solve the new problem.
  3. Divide and conquer:
    1. Break the problem down into stages.
    2. Solve the easy stages first - get something working.
    3. Can the hard ones also be broken down into further stages?
  4. Think about a real world analogy
    1. Imagine this problem in real life.
    2. Write a set of instructions for how you would do it.
    3. Now convert these instructions into a plan for your code.

Still stuck?

  • Ask the person next to you.
  • Ask your tutor
    • If you're tutor isn't there, Email them.
    • Don't by shy - your tutor is paid to help you.

A hard copy of this crib sheet is available.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License