Correcting Errors Challenge Below is the fixed code from the Identifying and Correcting Errors Class Notebook.

menu =  {"burger": 3.99,
         "fries": 1.99,
         "drink": 0.99,
         "checkout": 0}
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?
print("Please slelect an item. Then once your finished with the order type 'break' ")

checkout = 0
#ideally the code should prompt the user multiple times
for t, k in menu.items():
    item = input("Please select an item from the menu")
    if item == "break":
        break
    total = total + menu[item]

print("Total is: $" + str(total))

#code should add the price of the menu items selected by the user
Menu
burger  $3.99
fries  $1.99
drink  $0.99
checkout  $0
Please slelect an item. Then once your finished with the order type 'break' 
Total is: $12.96

Some Common Errors

No one is perfect. Errors are bound to happen but identifying, understanding, and fixing thoses errors is what matters more. There are 4 main types of errors when developing a program. These are Logic, Syntax, run-time, and overflow errors.

  • Over-flow errors occur in a program when it is required to perform a calculation that is not possible for it to run. The values in the calculations are outside the set range of values of the program. This is caused due to memory allocation constraints of the program's language, resulting in restrictions.

  • Run-time errors happen when a program stops while it is running. This event is also known as \"crashing\" and the error is normally referred to as a \"bug\". A run-time error can be caused by dividing by zero, wrong inputed data type, or many other errors that are commonly caused by incorrect data

  • Syntax errors are very small mistakes made by the programmer that doesn't match with the language. It could be a typo, unnecessary code, missing necessary code, missing characters or added characters. Characters include colon, semicolon, parenthesis, indentations, quotes, and so much more. These mistakes will cause the program to shut down.

  • Logic errors are errors that are caused due to the programmer making a mistake in the algorithm. This causes the program to behave unexpectedly. A logic error can result in events in the program taking place in times that they are not suppose to happen in.

How To correct Errors

  • Extra Outputs: Lastly, a programmer could just add extra outputs. This strategy is used so that the programmer could find where the error is in the program. When the error is fixed, the extra output is normally removed.

  • Hand Tracing: Another testing strategy is hand tracing. Hand tracing is putting in values of variables in a loop to find out if the outcome is correct. This is most useful with loops and other small code segments that repeat a number of times.

  • IDEs: Syntax errors are the easiest errors to fix because most IDEs display information on where and when there is a syntax error.

  • Test Cases: Unlike syntax errors, logic errors are more difficult to found because the IDEs doesn't help you and it would normally look like nothing is wrong. This is when programmers use test cases. Test cases are a set of actions(like inputs) that are used to check if they get the correct result.

Testing a Program

Programmers are planning program tests at the beginning of development. They determine the program's specifications and inputs and ask themselves how will they know if the program is working correctly. The Defined inputs used to test the program demonstrate different outcomes that would be expected, no matter if it works or not. When the inputs and outputs are matched, the programers test the code. After the test, programmers use the infomation that the program give them and revise, refine, and/or improve their work. Then they test again, make more changes, test again, and again. Once the programmers made clear results that they wanted, they let users test it and make more changes from that. After all that, the program is finished and can be released but even still, most of the time they will still be changes that must be fixed.

Hacks: Test Planning

  • What errors may arise in your project?

    • In program development, many errors eccour but most of them are small. These small errors could be an incorrect line of code, a typo, or a missed character. Most errors are like this but sometimes the error is bigger. Entire procedures can have the wrong purpose, code is typed using an incorrect language, program is set up incorrectly, and code could be blocked to some members of the team. All of these errors can break the entire code so ALL ERRORS MUST BE FIXED in our code.
  • What are some test cases that can be used?

    • The desried inputs for my team's program would be english words but we must test more than that. Test cases that can be used would include any word from any language with any amount of letters as well as numbers or other special characters. This would mostly likely break the code and that is why my group must test them. It would be the best way to fix them.