Video 1

Learning Objectives

For errors in an algorithm or program, the goal is to identify the error.

Essential Knowledge

There are four types of errors.

  • A logic error is a mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly.
  • A syntax error is a mistake in the program where the rules of the programming language are not followed.
  • A run-time ero-ror is a mistake in the program that occurs during the execution of a program. Programming languages define their own runtime errors.
  • An overflow error is an error that occurs when a computer attempts to handle a number that is outside of the defined range of values.

Programmers are constantly running into errors when they program.

  • In fact, it is an expectation that errors are a part of the programming process.
  • Proficient programmers can identify errors as one of the following types:
    • Logic error
      • this error is caused by programmer making a mistake in the algorithm, which causes the program to behave unexpectedly.
      • For example, the following code segment is intended to display the letter grade that corresponds to a percentage
    • Syntax error
      • this is a mistake when a programmer makes a type or writes some code that doesn't follow the rules of the language
      • syntax errors cause the program to fail to run/compile
      • common examples of this are forgetting to include:
        • colon/semicolon
        • parenthesis
        • curly braces
        • indentation
        • quotes
        • variable definition
    • Run-time error
      • A run-time error is when a program fails in the midst of running
      • This error is commonly referred to as a "bug"
      • The key to identifying a run-time error is that the program runs/compiles initially, but fails and cannot complete its processes
      • A run-time error may result from:
        • dividing by zero
        • inappropriately entered data type
        • many other advanced possibilities
    • Overflow error
      • an overflow error is when a program is required to perform a calculation that is outside of defined range of values
      • Due to memory allocation constraints that programming languages require, certain values are too big to calculate and/or display

Video 2

Learning Objectives

For errors in an algorithm or program, the goal is to correct the error.

Essential Knowledge

The following are effective ways to find and correct errors:

  • test cases
  • hand tracing
  • visualizations
  • debuggers
  • adding extra output statement

What do we do once we have identified an error?

The easiest error to correct is usually the syntax error.

  • Most integrated development environments (IDEs) display information when there is a syntax error
  • This information usually directs the programmer to the line in the program where the error has occurred
  • Sometimes the user needs to do a little digging to find the error The more difficult errors to find and correct are logic errors.
  • A logic error is not always immediately noticed
  • Using test cases is the first strategy programmers use to find logic errors
  • For example, the program on the next slide can be used to display a letter grade that corresponds to a percentage, but does not work correctly due to a logic error.

The next strategy to try is hand tracing

Hand tracing can be most useful with iteration.

  • Hand tracing is simply writing out the values of the variables within the loop as it iterates to determine if the outcome is correct
  • Hand tracing can be useful for small code segments and loops that iterate a small number of times
  • Larger code segments or loops might require a debugging program

What did hand tracing find out?

  • Hand tracing showed us that the algorithm was actually just displaying the last time a number was less than the number after if in a list
  • What if we used {1, 4, 0, 3, 2} as our list?
  • The algorithm would have displayed 0 as the minimum
  • Hence the need for multiple, varying test cases.
  • To correct this algorithm, we would need to ask if the min < list[index] rather than list[index] < list[index+1]
  • And repeat LENGTH(list) times

Another strategy is adding extra output statements

  • A programmer would use this strategy to help find and fix an error.
  • Once the error is corrected, the extra output statements are usually removed.
  • This has a similar effect as hand tracing, but allows the computer to do more of the work.

Video 3

Learning Objectives

Identify inputs and corresponding expected outputs or behaviors that can be used to check the correctness of an algorithm or program

Essential Knowledge

  • In the development process, testing uses defined inputs to ensure that an algorithm or program is producing the expected outcomes. Programmers use the results from testing to revise their algorithms or programs
  • Defined inputs used to test a program should demonstrate the different expected outcomes that are at or just beyond the extremes (minimum and maximum) of input data
  • Program requirements are needed to identify appropriate defined inputs for testing.

When do we start testing a program?

Programmers start testing a program at the onset of development

  • Or at least, they start thinking about testing
  • As soon as programmers determine the program specifications, they start trying to answer the question:
    • "How will we know if the program is working properly?"

Specifications influence testing

  • Recall that the program specifications list the behaviors, events, and corresponding responses/outputs the program is to support.
  • Programmers need to define inputs that will determine whether or not the program specifications are met

How does this influence program development?

  • Once the inputs and corresponding outputs are determined, programmers test, test, and test.
  • After testing, programmers use the results the revise, refine, and improve their programs.
  • And then they test them again and again.
  • After the programmers test, then users test, and then the programmers refine even more,
  • And finally, the program is released.

Hacks

  • What errors may arise in your project?

There can be many errors in my project because I am a beginner at programming, but I believe I will have trouble with coding and have a lot of syntax errors.

  • What are some test cases that can be used?

I can use hand tracing and look over everything by hand.

  • Make sure to document any bugs you encounter and how you solved the problem.
menu =  {"burger": 3.99,
         "fries": 1.99,
         "drink": 0.99}
total = 0

#shows the user the menu and prompts them to select an item
print("Menu")
for k,v in menu.items():
    print(k + "  $" + str(v)) #why does v have "str" in front of it?

#ideally the code should prompt the user multiple times
item = input("Please select an item from the menu")

total = menu[item]

#code should add the price of the menu items selected by the user 
print(total)
Menu
burger  $3.99
fries  $1.99
drink  $0.99
1.99