Learn AI-Assisted Python Programming

Book description

Writing computer programs in Python just got a lot easier! Use AI-assisted coding tools like GitHub Copilot and ChatGPT to turn your ideas into applications faster than ever.

AI has changed the way we write computer programs. With tools like Copilot and ChatGPT, you can describe what you want in plain English, and watch your AI assistant generate the code right before your eyes. It’s perfect for beginners, or anyone who’s struggled with the steep learning curve of traditional programming.

In Learn AI-Assisted Python Programming: With GitHub Copilot and ChatGPT you’ll learn how to:

  • Write fun and useful Python applications—no programming experience required!
  • Use the Copilot AI coding assistant to create Python programs
  • Write prompts that tell Copilot exactly what to do
  • Read Python code and understand what it does
  • Test your programs to make sure they work the way you want them to
  • Fix code with prompt engineering or human tweaks
  • Apply Python creatively to help out on the job

Learn AI-Assisted Python Programming: With GitHub Copilot and ChatGPT is a hands-on beginner’s guide that is written by two esteemed computer science university professors. It teaches you everything you need to start programming Python in an AI-first world. You’ll hit the ground running, writing prompts that tell your AI-assistant exactly what you want your programs to do. Along the way, you’ll pick up the essentials of Python programming and practice the higher-level thinking you’ll need to create working apps for data analysis, automating tedious tasks, and even video games.

About the Technology
The way people write computer programs has changed forever. Using GitHub Copilot, you describe in plain English what you want your program to do, and the AI generates it instantly.

About the Book
This book shows you how to create and improve Python programs using AI—even if you’ve never written a line of computer code before. Spend less time on the slow, low-level programming details and instead learn how an AI assistant can bring your ideas to life immediately. As you go, you’ll even learn enough of the Python language to understand and improve what your AI assistant creates.

What's Inside
  • Prompts for working code
  • Tweak code manually and with AI help
  • AI-test your programs
  • Let AI handle tedious details


About the Reader
If you can move files around on your computer and install new programs, you can learn to write useful software!

About the Authors
Dr. Leo Porter is a Teaching Professor at UC San Diego. Dr. Daniel Zingaro is an Associate Teaching Professor at the University of Toronto. The technical editor on this book was Peter Morgan.

Quotes
...masterfully blends the basics of programming with the effective use of AI tools to produce code.
- Mehran Sahami, Stanford University

This is such a well thought out book from the point of view of someone just starting to code post generative AI tools.
- Ana Bell, MIT

You are about to learn programming with one of the most exciting human task - supporters of this century...
- From the foreword by Beth Simon, UC San Diego

This book accelerates your Copilot programming learning journey beyond what I ever thought possible.
- Austin Z. Henley, Microsoft

Table of contents

  1. inside front cover
  2. Learn AI-Assisted Python Programming
  3. Copyright
  4. dedication
  5. contents
  6. front matter
    1. foreword
    2. acknowledgments
    3. introduction
      1. AI assistants change how programming is done
      2. Audience
      3. What we expect from you
      4. What you will be able to do after reading this book
      5. The challenge in working with AI assistants
      6. Why we wrote this book
      7. Warning: beware of elitism
      8. How this book is organized: a roadmap
      9. Source code downloads
      10. Software/hardware requirements
      11. liveBook discussion forum
    4. about the authors
    5. about the cover illustration
  7. 1 Introducing AI-assisted programming with Copilot
    1. 1.1 How we talk to computers
      1. 1.1.1 Making it a little easier
      2. 1.1.2 Making it a lot easier
    2. 1.2 About the technology
      1. 1.2.1 Copilot, your AI Assistant
      2. 1.2.2 How Copilot works behind the scenes—in 30 seconds
    3. 1.3 How Copilot changes how we learn to program
    4. 1.4 What else can Copilot do for us?
    5. 1.5 Risks and challenges when using Copilot
    6. 1.6 The skills we need
    7. 1.7 Societal concerns about AI code assistants like Copilot
    8. Summary
  8. 2 Getting started with Copilot
    1. 2.1 Time to set up your computer to start learning
      1. 2.1.1 Overview of the software in your programming environment
    2. 2.2 Getting your system set up
    3. 2.3 Working with Copilot in Visual Studio Code
      1. 2.3.1 Set up your working folder
      2. 2.3.2 Check to see if your setup is working properly
    4. 2.4 Addressing common Copilot challenges
    5. 2.5 Our first programming problem
      1. 2.5.1 Showcasing Copilot’s value in a data processing task
    6. Summary
  9. 3 Designing functions
    1. 3.1 Functions
      1. 3.1.1 The components of a function
      2. 3.1.2 Using a function
    2. 3.2 Benefits of functions
    3. 3.3 Roles of functions
    4. 3.4 What’s a reasonable task for a function?
      1. 3.4.1 Attributes of good functions
      2. 3.4.2 Examples of good (and bad) leaf functions
    5. 3.5 The cycle of design of functions with Copilot
    6. 3.6 Examples of creating good functions with Copilot
      1. 3.6.1 Dan’s stock pick
      2. 3.6.2 Leo’s password
      3. 3.6.3 Getting a strong password
      4. 3.6.4 Scrabble scoring
      5. 3.6.5 The best word
    7. Summary
  10. 4 Reading Python code: Part 1
    1. 4.1 Why we need to read code
    2. 4.2 Asking Copilot to explain code
    3. 4.3 Top 10 programming features you need to know: Part 1
      1. 4.3.1 #1. Functions
      2. 4.3.2 #2. Variables
      3. 4.3.3 #3. Conditionals
      4. 4.3.4 #4. Strings
      5. 4.3.5 #5. Lists
      6. 4.3.6 Conclusion
    4. Summary
  11. 5 Reading Python code: Part 2
    1. 5.1 Top 10 programming features you need to know: Part 2
      1. 5.1.1 #6. Loops
      2. 5.1.2 #7. Indentation
      3. 5.1.3 #8. Dictionaries
      4. 5.1.4 #9. Files
      5. 5.1.5 #10. Modules
    2. Summary
  12. 6 Testing and prompt engineering
    1. 6.1 Why it is crucial to test code
    2. 6.2 Closed-box and open-box testing
      1. 6.2.1 Closed-box testing
      2. 6.2.2 How do we know which test cases to use?
      3. 6.2.3 Open-box testing
    3. 6.3 How to test your code
      1. 6.3.1 Testing using the Python prompt
      2. 6.3.2 Testing in your Python file (we won’t be doing it this way)
      3. 6.3.3 doctest
    4. 6.4 Revisiting the cycle of designing functions with Copilot
    5. 6.5 Full testing example
      1. 6.5.1 Finding the most students we can add to a row
      2. 6.5.2 Improving the prompt to find a better solution
      3. 6.5.3 Testing the new solution
    6. 6.6 Another full testing example—Testing with files
      1. 6.6.1 What tests should we run?
      2. 6.6.2 Creating the function
      3. 6.6.3 Testing the function
      4. 6.6.4 Common challenges with doctest
    7. Summary
  13. 7 Problem decomposition
    1. 7.1 Problem decomposition
    2. 7.2 Small examples of top-down design
    3. 7.3 Authorship identification
    4. 7.4 Authorship identification using top-down design
    5. 7.5 Breaking down the process subproblem
      1. 7.5.1 Figuring out the signature for the mystery book
    6. 7.6 Summary of our top-down design
    7. 7.7 Implementing our functions
      1. 7.7.1 clean_word
      2. 7.7.2 average_word_length
      3. 7.7.3 different_to_total
      4. 7.7.4 exactly_once_to_total
      5. 7.7.5 split_string
      6. 7.7.6 get_sentences
      7. 7.7.7 average_sentence_length
      8. 7.7.8 get_phrases
      9. 7.7.9 average_sentence_complexity
      10. 7.7.10 make_signature
      11. 7.7.11 get_all_signatures
      12. 7.7.12 get_score
      13. 7.7.13 lowest_score
      14. 7.7.14 process_data
      15. 7.7.15 make_guess
    8. 7.8 Going further
    9. Summary
  14. 8 Debugging and better understanding your code
    1. 8.1 What causes errors (bugs)?
    2. 8.2 How to find the bug
      1. 8.2.1 Using print statements to learn about the code behavior
      2. 8.2.2 Using VS Code’s debugger to learn about the code behavior
    3. 8.3 How to fix a bug (once found)
      1. 8.3.1 Asking Copilot to fix your bug via chat
      2. 8.3.2 Giving Copilot a new prompt for the whole function
      3. 8.3.3 Giving Copilot a targeted prompt for part of a function
      4. 8.3.4 Modifying the code to fix the bug yourself
    4. 8.4 Modifying our workflow in light of our new skills
    5. 8.5 Applying our debugging skills to a new problem
    6. 8.6 Using the debugger to better understand code
    7. 8.7 A caution about debugging
    8. Summary
  15. 9 Automating tedious tasks
    1. 9.1 Why programmers make tools
    2. 9.2 How to use Copilot to write tools
    3. 9.3 Example 1: Cleaning up email text
      1. 9.3.1 Conversing with Copilot
      2. 9.3.2 Writing the tool to clean up email
    4. 9.4 Example 2: Adding cover pages to PDF files
      1. 9.4.1 Conversing with Copilot
      2. 9.4.2 Writing the tool
    5. 9.5 Example 3: Merging phone picture libraries
      1. 9.5.1 Conversing with Copilot
      2. 9.5.2 Top-down design
      3. 9.5.3 Writing the tool
    6. Summary
  16. 10 Making some games
    1. 10.1 Game programs
    2. 10.2 Adding randomness
    3. 10.3 Example 1: Bulls and Cows
      1. 10.3.1 How the game works
      2. 10.3.2 Top-down design
      3. 10.3.3 Parameters and return types
      4. 10.3.4 Implementing our functions
      5. 10.3.5 Adding a graphical interface for Bulls and Cows
    4. 10.4 Example 2: Bogart
      1. 10.4.1 How the game works
      2. 10.4.2 Top-down design
      3. 10.4.3 Implementing our functions
    5. Summary
  17. 11 Future directions
    1. 11.1 Prompt patterns
      1. 11.1.1 Flipped interaction pattern
      2. 11.1.2 Persona pattern
    2. 11.2 Limitations and future directions
      1. 11.2.1 Where Copilot (currently) struggles
      2. 11.2.2 Is Copilot a new programming language?
    3. Summary
  18. references
  19. index

Product information

  • Title: Learn AI-Assisted Python Programming
  • Author(s): Leo Porter, Daniel Zingaro
  • Release date: December 2023
  • Publisher(s): Manning Publications
  • ISBN: 9781633437784