Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

AI coding assistants can write code because they have learned patterns from huge collections of text and programs. They do not understand code like a human programmer, but they can predict what code is likely to come next from a prompt. This matters because students can use AI to explore ideas, debug errors, and learn faster when they also check the results carefully.

AI is a helper, not a replacement for understanding the problem.

Key Facts

  • An AI coding assistant predicts the next token using P(next token | context).
  • A token can be a word, symbol, number, or piece of code such as print or ==.
  • Training adjusts model weights to reduce error, often written as minimize loss L.
  • The prompt plus previous output is the context the model uses to generate code.
  • AI-generated code should be tested with inputs and expected outputs before it is trusted.
  • Good prompts include the goal, programming language, constraints, and examples.

Vocabulary

Artificial intelligence
Artificial intelligence is computer software designed to perform tasks that usually require human thinking, such as recognizing patterns or generating text.
Machine learning
Machine learning is a method where a computer improves at a task by finding patterns in data instead of being directly programmed with every rule.
Token
A token is a small unit of text, such as a word, symbol, or code fragment, that an AI model processes one piece at a time.
Prompt
A prompt is the instruction or question a user gives an AI system to guide its response.
Debugging
Debugging is the process of finding and fixing errors in code so the program works as intended.

Common Mistakes to Avoid

  • Assuming AI code is automatically correct is wrong because the model predicts likely text, not guaranteed truth. Always run tests and inspect the logic.
  • Writing a vague prompt is a mistake because the AI may fill in missing details incorrectly. Include the language, task, input format, output format, and constraints.
  • Copying AI code without understanding it is a mistake because you may not notice bugs, security problems, or inefficient logic. Read each part and explain what it does.
  • Testing only one example is a mistake because code can pass a simple case but fail on edge cases. Try normal inputs, small inputs, large inputs, and unusual inputs.

Practice Questions

  1. 1 A student asks an AI to write a program that converts 5 temperatures from Celsius to Fahrenheit using F = 1.8C + 32. What Fahrenheit values should the correct code output for C = 0, 10, 20, 30, and 100?
  2. 2 An AI model generates 120 tokens of code per second. About how long will it take to generate a 900-token program, assuming the speed stays constant?
  3. 3 A coding assistant gives a program that works for positive numbers but fails for zero and negative numbers. Explain how the student should revise the prompt and test plan to get a better answer.