Learn AI-Assisted Python Programming

Chapter 2: Getting Started with Copilot

  1. P.28 We gave Copilot three prompts.
    1. Handle the input data.
    2. Process data.
    3. Output the result.

Chapter 3: Designing Functions

  1. Simple examples about functions for junior high school students:
    1. age(yr)
    2. circle_area(r)
  2. P.41 Press "Shift - Enter" (or right-click - Run Python - Run Selection/Line in Python Terminal) to Run the selected code.
  3. P.45 Press "Ctrl - Enter" to ask Copilot to suggest alternative code.
  4. P.56 Code executes sequentially.

Chapter 4

  1. P.65 Working at a line level generally precedes the ability to work at an overall-purpose level [1].
  2. Select a segment of code, and then
    1. Ctrl-Alt-I : Open Chat, /explain
    2. or simply right-click - Explain
  3. P.70 Ctrl+Shift+P and type "REPL", select "Python: Start Terminal REPL". This will start the Python interpreter so that you can start doing experiments.
  4. P.72 A variable is a name that refers to a value. Whenever we need to remember a value for later, we use a variable.
  5. P.76 A method is a function that's associated with a particular data type.
  6. File - Preference - Keyboard Shortcuts

Chapter 5

  1. P.105 zipfile module

Chapter 6: Testing and Prompt Engineering

  1. P.110 Copilot can generate tests, but we encourage you to hold off on using Copilot to generate tests just yet because you need to learn to do this well enough on your own to be able to verify that the tests Copilot produces are reasonable.
  2. P.111 Regression Test - every time someone changes code, tests are run.
  3. TDD (test-driven development)
  4. P.116 pytest is a module that needs to be installed before it can be used.
  5. P.118 doctest module
    
            def age(y):
                '''
                Given the year which you were born,
                return your current age.
    
                >>> age(2026)       # Write your test cases in docstring
                0
                >>> age(1999)
                27
                '''
    
                return 2026 - y
    
            import doctest
            doctest.testmod(verbose=True) 
  6. P.123 In docstring, if a test case spans across multiple lines, continuation (\) is required.

Chapter 7: Problem Decomposition

  1. P.138 Part of the power of being a programmer is customizing what we're creating
  2. P.139 We start with the large task we want to complete and break it down into smaller tasks.
  3. p.141 Spelling suggestions - sucessful or successful? Thorough or thourough? Acceptable or acceptible? Receive or recieve?
  4. Top-Down Design

Chapter 8: Debugging and Better Understanding Your Code

  1. P.160 There are three primary categories of bugs:
    1. Syntax errors
    2. Run-time errors
    3. Logical errors
  2. You may insert print statements to learn about the code behavior, but where to put the print statements is an art more than a science.
  3. VS Code's Debugger: https://code.visualstudio.com/docs/debugtest/debugging
  4. P.164 Once you hit the breakpoint, you'll be able to inspect variable values and step through the program line by line.
  5. P.166 You may add the expression "dan" in word.lower() to the Watch section to see the True/False value.
  6. The <module> shown in the Call Stack section refers to the main function.
  7. Debug Toolbar

Chapter 9: Automating Tedious Tasks

  1. Tasks:
    1. After a mail has been forwarded several times, there will be multiple "> " in front of the text. Write a program to remove them.
    2. Suppose you have 100 reports (PDF files). You also have 100 different covers (also PDF files) for each of them. Write a program to merge each cover with its corresponding report.
    3. Compare your photo images and delete duplicate ones.
  2. P.186 As programmers, we don't want to do repetitive, boring, tedious work because that's what computers are good at.
  3. As soon as programmers notice that they are repeating the same steps over and over, they'll stop and make a tool to automate it.
  4. Tools are programs that do something that saves our time.
  5. P.187 Copilot Chat is built into Visual Studio Code (VS Code) IDE, so it has access to the code we're currently writing. That's why it can provide pertinent answers to us.
  6. We simply write the function header and a docstring. Copilot will fill in the code for us.
  7. A function will help us document our code, and it enables flexibility if we later decide to add additional parameters to our function to change the behavior of the tool.
  8. str.splitlines()
  9. s = '> > > > > Hello'; s.lstrip('> ') will remove those leading '> ' and get you "Hello".
  10. P.199 PyPDF2 module is good at reading and manipulating existing PDF files.
  11. To generate a PDF file from plain text, you may consider "reportlab" and "fpdf".
  12. os.listdir()
  13. pip install "PyPDF2 < 3.0.0" # Install a version prior to 3.0.0
  14. if not os.path.exists(dir): os.mkdir(dir)
  15. filecmp.cmp(filename1, filename2)
  16. x = filecmp.dircmp(dirname1, dirname2); x.report() # This one is good

Chapter 10: Making Some Games

  1. P.222 Many games rely on randomness to make them fun.
  2. Games:
    1. Bulls and Cows (https://www.mathsisfun.com/games/bulls-and-cows.html)
    2. Wordle
    3. Bogart
    4. The Price Is Right
  3. P.229 Using parameters and variables to avoid magic numbers.

Chapter 11: Creating an Authorship Identification Program

  1. P.256 We cherry-picked (精心挑選) these two excerpts.
  2. P.259 Signature: Features to identify an author:

Chapter 12: Future Directions

  1. P.287 Design patterns: elements of reusable object-oriented software
  2. not reinventing the wheel
  3. huge functions are not easy to design and test.
  4. Prompt patterns - similar to design patterns. However, rather than example code, we get example prompts that we can use.
  5. In this book, we've spent most of our time on two types of AI responses: generating code (by pressing Tab in VS Code) and explaining code (by using Copilot Chat). Yet, there are other ways to interact with AI.
  6. P.289 Flipped Interaction Pattern: AI does the asking and we do the answering.
  7. Persona pattern
  8. P.298 Whether you are writing code occasionally at work to automate tedious tasks or you're planning to become a professional software engineer, you should learn essential skills that everyone needs to create good software.
  9. Annapurna Vadaparty, Daniel Zingaro, David H. Smith IV, Mounika Padala, Christine Alvarado, Jamie Gorson Benario, and Leo Porter. "CS1-LLM: Integrating LLMs into CS1 Instruction." In Proceedings of the 29th ACM Conf. on Innovation and Technology in Computer Science Education (ITiCSE 2024), V.1, pp.297–303. July 2024, New York, NY, USA. https://doi.org/10.1145/3649217.3653584
  10. Albadarin, Y., Saqr, M., Pope, N. et al. "Evaluating the Effect of Generative AI-Assisted Debugging on Students' Critical Thinking." Tech Know Learn (2026). https://doi.org/10.1007/s10758-026-09998-z