Correcting Errors Challenge

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

menu =  {"burger": 3.99,    # creates the menu, its components, and each component's price.
         "fries": 1.99,
         "drink": 0.99,
         "checkout": 0}     # 'checkout' is created in the table in order for it to be an interactive input.
total = 0                   # creates the variable 'total' and sets it to 0.

print("Menu")               # prints menu's components.
for k,v in menu.items():    # 'k' = item's name. 'v' = item's price(numeric value).
    print(k + "  $" + str(v)) #str changes a numeric value (v) into a character that can be printed.
print("Please select an item. Type 'checkout' to finish your order.") #tells users what they can do.

checkout = 0                # checkout created and set to 0.
while checkout == 0:        # while loop connected to checkout.
    item = input("Please select an item from the menu Type 'checkout' to finish.") #tells users what they can do.
    item = item.lower()     #changes input to lowercase to be user friendly.
    if item == "burger" or item == "fries" or item == "drink": #this if statement allows for muiltple inputs to have the same output.
        print( item, "will be $" + str(menu[item])) #prints item info.
        total += menu[item]  # adds the price of the item to total price.
    else:
        if item == "checkout":
            checkout = 1    #Changes value of checkout that ends while loop.
        else:
            print("Try again, that item is not on the menu") #In case user makes a typo or tpyes an unknown item.
else:
    myorder = "Your total is ${:.2f}! Enjoy!"                #source: w3shools.com Python String Formatting
    print(myorder.format(total))
Menu
burger  $3.99
fries  $1.99
drink  $0.99
checkout  $0
Please select an item. Type 'checkout' to finish your order.
burger will be $3.99
fries will be $1.99
drink will be $0.99
Your total is $6.97! Enjoy!

Common Errors to Identify:

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Ways to Correct Errors:

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

  2. 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.

  3. 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.

  4. 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.

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.