Checking AI-generated code

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Checking AI-generated code

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. An AI tool gives you code that solves your task. What should you do first?
A Paste it into your project and submit it
B Read the code and make sure you understand it
2. Which is the best way to test AI-generated code against the requirements?
A Use a test table with inputs, expected results and actual results
B Run it once and assume it works if no error appears
3. The AI code runs without any error message. What does that tell you?
A Only that it has no syntax or runtime errors; it may still give wrong results
B The code is correct and meets every requirement
4. Your program needs to accept ages from 12 to 18. The AI code accepts 11. Which type of error is this?
A A syntax error that the editor would have flagged
B A logic error that testing with boundary data should find
5. Why should you check AI-generated code for bias?
A It may treat some users or groups unfairly because of its training data
B AI code is always neutral because a computer wrote it

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1# Generated by ChatGPT, checked and edited by me AThe code was not read or tested against the requirements, so errors could remain and the student may not understand it
2Test table: input 50, expected 50, actual 45 BA comment that acknowledges the AI tool used, and states that the student has checked the code
3Read the AI code and explain each line before you run it C# Line 3: loop through each mark and add it to total
4Check the code for bias, such as unfair rules built into a decision DA test shows the code does not meet the requirements, because the actual output differs from the expected output
5Pasted the AI code into my program and handed it in without running it Eif gender == "female": discount = 0
6# Code written by me (it was copied from an AI tool) FThe AI tool is not acknowledged, so the comment wrongly claims the student wrote it all

Definitions

Check AI code

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
_ Code generated by ChatGPT, checked by me
2.
print(average([2, 4, 6])) # expected: _
3.
def average(nums): return sum(nums) / ___(nums)
4.
def average(nums): if len(nums) __ 0: return 0
5.
tests = [(2, 3, 5), (0, 0, 0)] for a, b, expected in tests: print(add(a, b) __ expected)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A # Written by me, no AI used
B def average(m):
C return sum(m) / len(m)
Question 2
A def is_pass(mark):
B return mark > 50
C print(is_pass(50))
D # Test: 50 expects True
Question 3
A # Task: total of 3 prices
B prices = [4, 6, 10]
C total = sum(price)
D print(total)
Question 4
A marks = [70, 85, 90]
B total = 0
C for m in marks:
D total = m
E print(total / len(marks))
Question 5
A names = ['Ava', 'Liam', 'Zoe']
B for n in names:
C if n[0] < 'M': print(n)

Answer Key

Checking AI-generated code
Section A: Quick Questions
Q1
B — Read the code and make sure you understand it
Q2
A — Use a test table with inputs, expected results and actual results
Q3
A — Only that it has no syntax or runtime errors; it may still give wrong results
Q4
B — A logic error that testing with boundary data should find
Q5
A — It may treat some users or groups unfairly because of its training data
Section B: Match the Pairs
Q1
# Generated by ChatGPT, checked and edited by me → A comment that acknowledges the AI tool used, and states that the student has checked the code
Q2
Test table: input 50, expected 50, actual 45 → A test shows the code does not meet the requirements, because the actual output differs from the expected output
Q3
Read the AI code and explain each line before you run it → # Line 3: loop through each mark and add it to total
Q4
Check the code for bias, such as unfair rules built into a decision → if gender == "female": discount = 0
Q5
Pasted the AI code into my program and handed it in without running it → The code was not read or tested against the requirements, so errors could remain and the student may not understand it
Q6
# Code written by me (it was copied from an AI tool) → The AI tool is not acknowledged, so the comment wrongly claims the student wrote it all
Section C: Definitions
Q1
Check AI code — Read AI-generated code, test it against the requirements and check it for errors, bias and copyright issues before you use it. Then acknowledge the AI tool you used.
Section D: Fill in the Blanks
Q1
# Code generated by ChatGPT, checked by me
Q2
print(average([2, 4, 6])) # expected: 4
Q3
def average(nums): return sum(nums) / len(nums)
Q4
def average(nums): if len(nums) == 0: return 0
Q5
tests = [(2, 3, 5), (0, 0, 0)] for a, b, expected in tests: print(add(a, b) == expected)
Section E: Spot the Error
Q1
A — The code was made by an AI tool, so the comment must acknowledge it, for example '# AI tool: ChatGPT, 3 May 25'. It must not claim the work is all your own.
Q2
B — The test table expects 50 to pass, but > 50 returns False for 50. It should be >= 50. Testing boundary values finds this kind of AI error.
Q3
C — Reading the code before running it shows that 'price' is never defined. The list is called 'prices', so it should be sum(prices).
Q4
D — This replaces the total with the latest mark instead of adding to it, so the average is wrong. It should be total += m. A test table with a known expected average would catch this.
Q5
C — This filter quietly leaves out users whose names come after M, which is a bias in the AI code. Every user should be welcomed, so the line should be print('Welcome', n).