Skip to content
⚠️ This document is AI-translated. The Chinese version is the authoritative source.

AI Programming Basics

What This Tutorial Teaches

You'll learn to code with an AI assistant — no programming background required, and no need to learn any programming language beforehand. The AI assistant will help you translate natural language (plain everyday words) into code that computers can execute.

  • Estimated time: 30-45 minutes
  • Final deliverable: A working Python countdown program written with AI
  • Prerequisites: A computer (macOS or Windows), internet connection

Ready? Let's begin.


Part 1: Key Concepts (5-minute read)

Before getting hands-on, let's spend a few minutes understanding some concepts you'll encounter repeatedly. No need to memorize them — you'll become more familiar as you use them later.

AI Programming Assistant = A Chat Partner Who Knows How to Code

An AI programming assistant is not a search engine (it doesn't "search for answers"), nor is it an automatic code-writing machine (it can't do everything for you). It's more like a programming buddy who's always online: you tell it what you want to do in plain language, and it helps you write code, explain code, and find bugs. But the final call is yours — you need to judge whether what it gives you is correct.

For a detailed explanation, see Glossary - Claude Code

API = A Conversation Interface Between Programs

Imagine eating at a restaurant: you read the menu and order food (speaking your language), the waiter translates your request to the kitchen (which has its own "language"), and the kitchen prepares the dish and serves it to you. In this process, the menu and the waiter are the "API" — they define how you and the kitchen communicate. Programs work the same way, passing data to each other through APIs.

For a detailed explanation, see Glossary - API

API Key = Your ID Card

Just like you need a library card to borrow books, you need an API Key to use AI services — it proves "I'm a legitimate user." It's a string of seemingly random characters, unique to each person. Keep it safe after you get it, and don't share it with others — just like you wouldn't tell a stranger your bank PIN.

For a detailed explanation, see Glossary - Token (an API Key is a type of Token)

Token = AI's Billing Unit

When AI processes text, it breaks your input into small pieces called tokens. Think of it like mobile data — you pay for what you use. One Chinese character is roughly 1-2 tokens; one English word is roughly 1 token. A 100-word conversation consumes about 100-200 tokens. Most platforms give new users free credits, which are more than enough for learning.

For a detailed explanation, see Glossary - Token

IDE = A Tool for Writing Code

Word is a tool for writing documents, Photoshop is a tool for editing images, and an IDE (Integrated Development Environment) is a tool for writing code. The most popular one right now is VS Code — free, user-friendly, and rich with plugins. Think of it as a "supercharged notepad" optimized for coding: it color-codes your code, auto-completes, and helps you spot errors.

This tutorial primarily uses a terminal-based AI assistant. VS Code will be used in later tutorials.

Terminal / Command Line = Operating Your Computer with Text

Normally you click icons with a mouse to open software and copy files. The terminal (also called command line) is another way to operate your computer — with text. You type a command, press Enter, and the computer executes it. It sounds primitive, but programmers use it every day because many tasks are much faster with commands than with a mouse.

For a detailed explanation, see Glossary - CLI


Part 2: Setting Up Your Environment

This step requires installing some tools on your computer. We've prepared a detailed installation guide — just follow the steps.

Please follow Environment Setup Guide to complete steps 1-7. Come back here when you're done.

Verification point: Type claude --version in your terminal. Seeing a version number means the installation was successful.

If you run into issues during installation, each step in the environment setup guide has a "Common Issues" collapsible section — expand it to see if your situation is covered.


Part 3: Register for Zhipu AI and Get Your API Key

Claude Code is a "framework" — it needs to connect to an AI model to work. We'll use Zhipu AI (a Chinese platform that's easy to register for and offers free credits).

The following steps are based on the Zhipu Open Platform interface as of March 2026. If anything has changed, please refer to the actual website.

3.1 Register a Zhipu Account

  1. Open your browser and visit Zhipu Open Platform
  2. Click the "Register" button in the top-right corner
  3. Register with your phone number and enter the verification code to complete registration
  4. After successful registration, you'll be automatically logged in

3.2 Get Free Credits

  1. After logging in, enter the console
  2. New users typically receive free trial credits (the exact amount depends on the platform's current policy)
  3. If the platform offers student verification, you can try verifying to get more free credits (requires a student ID or educational email)

3.3 Create an API Key

  1. Find "API Keys" in the left sidebar menu of the console
  2. Click the "Create API Key" button
  3. Give your Key a name (e.g., "For Learning"), then click confirm
  4. The page will display your API Key — immediately copy and save it somewhere safe (like a notes app)

Warning: Security Tips:

  • The API Key is shown only once. After closing the page, you can't view it again — you'll have to create a new one
  • Don't share your API Key with others — if someone uses your Key to call the API, it's your credits that get consumed
  • Don't commit your API Key to a Git repository — this is one of the most common security incidents

Verification point: Your API Key should look like xxxxxxxx.xxxxxxxxxxxxxxxx (two strings separated by a dot). If the format doesn't match, you may have copied it incorrectly.


Part 4: Configure Claude Code to Use Zhipu

Now that you have an API Key, you need to tell Claude Code to use the Zhipu AI model. We'll use the cc-switch tool to complete this configuration.

4.1 Run cc-switch

Open your terminal and type:

bash
cc-switch

You'll see an interactive menu listing available AI providers.

4.2 Select Zhipu and Enter Your API Key

  1. Use the arrow keys to select zhipu, then press Enter to confirm
  2. Enter the API Key you saved earlier when prompted, then press Enter
text
? Select provider: zhipu
? Enter API Key: xxxxxxxx.xxxxxxxxxxxxxxxx
✓ Configuration saved

4.3 Verify the Configuration

In your terminal, type:

bash
claude "Hello, please introduce yourself in one sentence"

Wait a few seconds. If everything is set up correctly, the AI will respond with a self-introduction, something like:

text
Hello! I'm an AI language model that can help you with answering questions, writing code, analyzing text, and various other tasks.

Verification point: Seeing a response from the AI means the configuration was successful. If you get an error, check the following:

  • Is the API Key copied completely (no extra spaces or missing characters)?
  • Is your network working (can you open bigmodel.cn)?
  • Try running cc-switch again to reconfigure

Part 5: Complete Your First Programming Task with AI

Environment is ready. Now let's do something fun — use AI to write a Python countdown program.

5.1 Install Python

If you haven't installed Python yet, do it now.

macOS:

bash
brew install python

Windows (in an administrator PowerShell):

powershell
winget install Python.Python.3.12

Verify the installation:

bash
python3 --version

Seeing Python 3.x.x means you're good. On Windows, you may need to use python instead of python3.

5.2 Start a Conversation with AI

Open your terminal, type claude to enter conversation mode. Then tell it what you want to do, just like chatting:

You:

Write me a Python countdown program that counts down from 10 to 0, displaying one number per second

AI:

Sure, here's a simple countdown program:

python
import time

for i in range(10, -1, -1):
    print(i)
    time.sleep(1)

print("Countdown complete!")

Here's the logic:

  • range(10, -1, -1) generates a sequence of numbers from 10 to 0
  • print(i) displays the current number on screen
  • time.sleep(1) pauses the program for 1 second before continuing
  • Finally, it prints "Countdown complete!"

5.3 Run the Program

Ask AI to save the code to a file and run it:

You:

Save this code as countdown.py and run it

AI:

File countdown.py has been created. Here's the output:

text
10
9
8
7
6
5
4
3
2
1
0
Countdown complete!

Verification point: The terminal shows a countdown from 10 to 0, with approximately 1 second between each number.

5.4 Modify the Program with Natural Language

This is where AI programming gets really interesting — you don't need to learn syntax, just tell the AI what you want to change in plain language.

Try these modifications:

You:

Change the countdown to start from 30

AI:

Done. Changed range(10, -1, -1) to range(30, -1, -1). The output will now count down from 30.

Now try something more fun:

You:

Play a notification sound when the countdown finishes

AI:

Modified countdown.py:

python
import time
import os
import platform

for i in range(30, -1, -1):
    print(i)
    time.sleep(1)

print("Countdown complete!")

# Play notification sound
if platform.system() == "Darwin":  # macOS
    os.system("afplay /System/Library/Sounds/Glass.aiff")
elif platform.system() == "Windows":
    import winsound
    winsound.Beep(1000, 500)
else:
    print("\a")  # Generic terminal bell

The program will choose the appropriate method to play a notification sound based on your operating system.

Feel that? You haven't learned any programming syntax, yet you're already "writing programs." You handle the ideas, AI handles the translation to code. This is the core experience of AI programming.


Part 6: Fundamental Principles of AI Programming

Before you continue exploring, here are four principles to remember. They'll help you avoid most pitfalls that beginners fall into.

Principle 1: AI Is Not Infallible — It Makes Mistakes, and You Need to Verify

AI will confidently give you buggy code, like an enthusiastic but occasionally careless friend. So every time you get code from AI, run it first and check if the result is correct. If it's wrong, tell the AI what's wrong and ask it to fix it.

The right mindset: Treat AI's output as a "first draft," not a "final draft."

Principle 2: Good Questions = Good Results

The quality of AI's answers depends on the quality of your questions. "Write me a program" is too vague, but "Write me a Python countdown program that counts down from 10 to 0, displaying one number per second" is much clearer.

A few tips for asking good questions:

  • Be clear about what you want (feature description)
  • Be clear about what to use (programming language, tools)
  • Be clear about constraints (e.g., "don't use third-party libraries")

Principle 3: Iteration Is Normal — It's Fine If It's Not Perfect the First Time

Just like writing an essay, the first draft is rarely perfect. Conversations with AI are an iterative process: you describe requirements -> AI writes code -> you test -> find issues -> tell AI to fix -> test again. This cycle is a normal workflow, not a sign that "AI doesn't work."

Principle 4: Understand Before You Use — Don't Blindly Copy AI's Code

For code AI gives you, at least get a rough idea of what it's doing. You don't need to understand every line of syntax, but you should know the overall logic. That way, when the code has problems, you can tell AI what's wrong.

To learn more about these principles and additional workflow patterns, read AI Workflow Patterns.


Next Steps

Congratulations on completing your first AI programming task! Here's a recap of what you learned:

  • What an AI programming assistant is and how to use it
  • How to set up your environment and configure AI services
  • How to use natural language to have AI write and modify code
  • The four fundamental principles of AI programming

In the next tutorial, we'll use AI to develop a Presto template — turning your formatting ideas into a real, usable document template.

Continue reading: Develop Presto Templates with AI

Presto — Markdown to PDF