Back to 课程

Computer Science GCES OCR

0% Complete
0/0 Steps
  1. Cpu Architecture Performance And Embedded Systems Ocr
    5 主题
  2. Primary And Secondary Storage Ocr
    6 主题
  3. Data Storage And Compression Ocr
    12 主题
  4. Networks And Topologies Ocr
    6 主题
  5. Wired And Wireless Networks Protocols And Layers Ocr
    6 主题
  6. Identifying And Preventing Threats To Computer Systems And Networks Ocr
    2 主题
  7. Operating Systems And Utility Software Ocr
    2 主题
  8. Ethical Legal Cultural And Environmental Impact Ocr
    2 主题
  9. Computational Thinking Searching And Sorting Algorithms Ocr
    3 主题
  10. Designing Creating And Refining Algorithms Ocr
    5 主题
  11. Programming Fundamentals And Data Types Ocr
    5 主题
  12. Additional Programming Techniques Ocr
    7 主题
  13. Defensive Design And Testing Ocr
    6 主题
  14. Boolean Logic Diagrams Ocr
    2 主题
  15. Programming Languages And Integrated Development Environments Ides Ocr
    3 主题
  16. The Exam Papers Ocr
    2 主题
  17. Structuring Your Responses Ocr
    3 主题
课 Progress
0% Complete

Exam code:J277

What are syntax errors and logic errors?

  • Syntax errors and logic errors are thoroughly covered earlier in the course, you can find that revision note here

  • A summary of the two error types:

    • Syntax error: An error that breaks the grammatical rules of a programming language and stops it from running

    • Logic error: Incorrect code is used that allows the program to run, but produces an incorrect or undesired output

Identify Syntax & Logic Errors in Testing

How can you identify errors?

  • As a result of a syntax error breaking the rules of the programming language, the program will not execute

  • These are easily identifiable as the IDE will provide information about what the error is

    • This is done to help the programmer be able to fix the issue

  • To help practise this skill, a selection of program screenshots will be used

The errors

  • In the code below, there is a program which allows the user to enter how many items they wish to add to a shopping list

  • The code then allows the user to

    • Enter their chosen number of items into a list

    • Output the list to the screen

  • The code contains 3 syntax errors, highlighted with blue boxes

MN6hXX4I_screenshot-2024-02-28-at-09-16-13

Error 1

  • Line 3: Missing a second bracket at the end of integer input

    • The error message below is what the IDE provided to help the programmer identify the error

    • A top tip when programming is to look at the line of code above the one given in the error message

      • For example, this error message claims line 6 is the issue, however, the code above line 6 (line 3) is the line that contains the error

screenshot-2024-02-28-at-09-17-20

Error 2

  • Line 6: Missing a colon at the end of a for loop, while loop or if statement

    • As mentioned earlier, the error message identifies the line after the actual error

    • The error is on line 6, however, the syntax error message identifies the line below it

      • Always check the line above for any potential errors

screenshot-2024-02-28-at-09-18-48

Error 3

  • Line 7: Using == which is used for a comparison instead of a single = to declare a variable

    • This would return the same error as above, this time the user would more easily be able to identify the issue as it is on line 7

screenshot-2024-02-28-at-09-18-48

The fix

  • Once all fixes are in place, the code should appear as follows and the program should execute as intended

screenshot-2024-02-28-at-09-15-41
screenshot-2024-02-28-at-09-17-50

Identifying logic errors

  • Logic errors can be slightly more challenging to locate compared to syntax errors

  • This is because the program will still run but will not produce the expected output that the programmer intended

  • The most obvious areas to check for logic errors are:

    • Logical operators (<, >, ==, !=)

    • Boolean operators (AND, OR, NOT)

    • Division by 0

  • To help demonstrate this skill, another snippet of program code is used

r883LnnA_screenshot-2024-02-28-at-09-51-14
  • In this example, the incorrect Boolean operator has been used, OR instead of AND

  • The result means the else clause in the if statement would never be caught

<img alt=”screenshot-2024-02-28-at-09-51-20″ class=”ContentBlock_figure__vJw2q” data-nimg=”1″ decoding=”async” height=”76″ loading=”lazy” sizes=”(max-width: 320px) 320w, (max-width: 640px) 640w, (max-width: 960px) 960w, (max-width: 1280px) 1280w, 1920w” src=”https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=3840/https://cdn.savemyexams.com/uploads/2024/02/screenshot-2024-02-28-at-09-51-20.png” srcset=”https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=16/https://cdn.savemyexams.com/uploads/2024/02/screenshot-2024-02-28-at-09-51-20.png 16w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=32/https://cdn.savemyexams.com/uploads/2024/02/screenshot-2024-02-28-at-09-51-20.png 32w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=48/https://cdn.savemyexams.com/uploads/2024/02/screenshot-2024-02-28-at-09-51-20.png 48w, https://cdn.savemyexams.com/cdn-cgi/image/f=auto,width=64/https://cdn.savemyexams.com/uploads/2024/02/screenshot-2024-02-28-at-09-51-20.png 64w, https:

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注