Your first program · 你的第一个程序
Welcome
- Python follows your instructions, one line at a time.
- You write code here and run it — nothing to install.
- Read each step, then press Continue.
欢迎
- Python 会按照你的指令一行一行地执行。
- 你在这里写代码并运行 —— 无需安装任何东西。
- 读完每一步,然后按继续。
Show text with print
print(...)shows text on the screen.- Put the text in quotes:
"...". - Each
printstarts a new line.
用 print 显示文字
print(...)会把文字显示在屏幕上。- 把文字放进引号里:
"..."。 - 每个
print都会另起新的一行。
print("Welcome to Python!")
print("This line runs next.")
Strings
- Text in quotes is called a string.
- You can use double quotes
"..."or single quotes'...'. - You can also print a number with no quotes, like
print(42).
字符串
- 引号里的文字叫作字符串(string)。
- 你可以用双引号
"...",也可以用单引号'...'。 - 不加引号也可以打印一个数字,例如
print(42)。
Comments
- A line that starts with
#is a comment. - Python ignores comments — they do not run.
- Use them to leave notes for people who read your code.
注释
- 以
#开头的一行是注释(comment)。 - Python 会忽略注释 —— 它们不会运行。
- 用注释给阅读代码的人留下说明。
# This line is a note for people. Python skips it.
print("Comments do not show.")
Common mistakes
printneeds quotes around text:print("Hi"), notprint(Hi).- Python is case-sensitive:
Printis not the same asprint.
常见错误
print的文本要加引号:print("Hi"),不是print(Hi)。- Python 区分大小写:
Print和print不一样。
Now you try
- Below are a few tasks. Type your code and press Run.
- Press Check answer to see if it is correct.
现在轮到你
- 下面有几个任务。输入你的代码,然后按运行。
- 按检查答案看看是否正确。
How a program runs · 程序是怎么运行的
A program runs top to bottom, one statement at a time. · 程序从上到下,一次执行一条语句。
Use print(...) to make Python show the words Hello, world! exactly (same spelling, same punctuation). · 使用 print(...) 让 Python 精确地显示 Hello, world!(拼写和标点都要一样)。
Click Run to see the output here. · 点击“运行”查看此处输出。
Print two lines. The first line must be My name is Pat. The second line must be I am learning Python. (Use two print(...) calls.) · 打印两行。第一行必须是 My name is Pat,第二行必须是 I am learning Python。(使用两次 print(...)。)
Click Run to see the output here. · 点击“运行”查看此处输出。
Keep the comment line, then print the number 42. Notice the comment never appears in the output. · 保留那行注释,然后用 print 打印数字 42。注意注释永远不会出现在输出里。
Click Run to see the output here. · 点击“运行”查看此处输出。
Print a box made of three lines: first +-----+, then | Hi! |, then +-----+ again. · 打印一个由三行组成的方框:先 +-----+,再 | Hi! |,最后再打印一次 +-----+。
Click Run to see the output here. · 点击“运行”查看此处输出。