欢迎来到代码王国 | Welcome to the Code Kingdom
第 1 章:欢迎来到代码王国 | Welcome to the Code Kingdom
那是一个再普通不过的星期三下午。阳光透过学校图书馆高大的落地窗洒进来,在老旧的木质地板上投下斑驳的光影。空气中弥漫着旧书特有的气味——那种混合着纸张、墨水和岁月的独特芬芳。
It was an ordinary Wednesday afternoon. Sunlight streamed through the tall floor-to-ceiling windows of the school library, casting dappled patterns on the old wooden floors. The air was filled with the distinctive scent of old books—a unique blend of paper, ink, and the passage of time.
小明百无聊赖地靠在书架旁,手里捧着一本已经翻了无数遍的漫画书。他已经把这本书从头到尾看了三遍,连每一页的折角位置都记得清清楚楚。说实话,如果不是因为教室里太吵,同学们的嬉笑打闹让他根本无法完成数学作业,他才不会来这个“无聊透顶”的地方。
Xiao Ming leaned against the bookshelf, bored out of his mind, holding a comic book he'd already read countless times. He had gone through it from cover to cover at least three times, and could remember the exact location of every dog-eared page. Truth be told, if it weren't for the noise in the classroom—the laughter and horseplay of his classmates that made it impossible to finish his math homework—he wouldn't have come to this "utterly boring" place.
就在他准备合上书、打道回府的时候,一个奇怪的声音引起了他的注意。那声音很轻,轻得几乎被空调的嗡嗡声完全掩盖——但它确实存在,像是某种电子设备发出的微弱蜂鸣。
Just as he was about to close the book and head home, a strange sound caught his attention. It was very faint—so faint that the air conditioner's hum nearly drowned it out completely—but it was definitely there, like a soft electronic beep from some kind of device.
“咦?那是什么声音?”小明的好奇心瞬间被点燃了。
"Hmm? What's that sound?" Xiao Ming's curiosity was instantly sparked.
他顺着声音的方向走去,穿过一排排高大的书架,越往深处走,光线就越昏暗。那些平日里他从未留意过的角落里,堆满了落满灰尘的旧书和杂物。就在图书馆最深处、一个被遗忘的角落里,他看到了一台电脑。
He followed the direction of the sound, weaving through rows of towering bookshelves. The deeper he went, the darker the light became. In those forgotten corners he had never bothered to notice before, old dusty books and miscellaneous items were stacked in heaps. And there, in the deepest corner of the library—an utterly forgotten place—he spotted a computer.
这台电脑看起来老得不能再老了。它的外壳是那种已经很少见到的米白色,边角处布满了划痕和磨损的痕迹。显示器是那种老式的CRT显示器,圆滚滚的背部高高鼓起,活像一只趴在桌上打盹的胖猫咪。键盘上的字母已经被磨得模糊不清,好几个键帽上还沾着不知道是什么的污渍。
This computer looked impossibly old. Its casing was that rare beige color, with scratches and wear marks covering every corner. The monitor was an old-style CRT display with a bulging rounded back, just like a chubby cat dozing off on a desk. The letters on the keyboard had worn down to vague shadows, and several keycaps had mysterious stains on them.
小明从未见过这样的电脑。他家里用的是爸爸淘汰下来的笔记本电脑,虽然也是好几年前的老机器了,但至少屏幕是平的,开机也只要几秒钟。而眼前这台“古董”,看起来简直像是从爷爷奶奶那辈人家里刨出来的。
Xiao Ming had never seen a computer like this. His family used a laptop his dad had replaced, which, though several years old, at least had a flat screen and booted up in just a few seconds. But this "antique" in front of him looked like something excavated from his grandparents' generation.
然而,真正吸引小明注意的不是电脑的老旧,而是——它居然是开着的。
However, what really caught Xiao Ming's attention wasn't the computer's age—it was the fact that it was actually turned on.
屏幕上闪烁着柔和的蓝光,一个黑色的窗口静静地停留在那里。窗口里有一个闪烁的光标,像是在等待着什么,又像是在呼吸。那微弱的光芒在昏暗的角落里显得格外神秘,仿佛在对小明说:“来啊,来和我说话啊。”
On the screen, soft blue light flickered, and a black window sat quietly, waiting. Inside the window, a blinking cursor seemed to be waiting for something, or perhaps breathing. That faint glow appeared especially mysterious in the dim corner, as if saying to Xiao Ming: "Come on, come talk to me."
小明不由自主地在电脑前坐下。他的手指悬在键盘上方,犹豫了一下,然后轻轻地敲了几下。屏幕上的黑色窗口里,出现了一行他从未见过的文字:
Xiao Ming couldn't resist sitting down in front of the computer. His fingers hovered over the keyboard, hesitated, then gently tapped a few keys. In the black window on the screen, a line of text he had never seen before appeared:
```python >>> ```
“三个大于号?这是什么意思?”小明喃喃自语。他试着又敲了几个字母,但那台电脑似乎完全不理他,他输入的字母并没有出现在屏幕上。
"Three greater-than signs? What does this mean?" Xiao Ming muttered to himself. He tried typing a few more letters, but the computer seemed to completely ignore him—his input didn't appear on the screen.
就在小明困惑不已的时候,一个苍老而温和的声音从他身后传来:“那是Python的交互式环境,年轻人。”
Just as Xiao Ming was thoroughly confused, an elderly but warm voice came from behind him: "That's Python's interactive environment, young man."
小明猛地回头,看到一位白发苍苍的老人正站在书架旁边。老人戴着一副圆框眼镜,眼镜片后面的眼睛闪烁着慈祥而智慧的光芒。他穿着一件洗得有些发白的蓝色格子衬衫,袖子挽到手肘处,手里拿着一本厚厚的书。
Xiao Ming spun around to find an elderly man with silver-white hair standing beside the bookshelf. The old man wore round-framed glasses, and his eyes behind them sparkled with kindness and wisdom. He wore a light-blue plaid shirt, faded from countless washes, with the sleeves rolled up to his elbows, and held a thick book in his hands.
“你是谁?”小明警惕地问。
"Who are you?" Xiao Ming asked warily.
老人笑了,那笑容像是冬日里的暖阳,让人感到无比安心:“我姓李,是这所学校的退休信息技术老师。大家都叫我李老师,或者——如果你愿意的话——代码王国的守门人。”
The old man smiled, that smile like winter sunshine, making one feel completely at ease: "My surname is Li. I'm the retired Information Technology teacher from this school. Everyone calls me Teacher Li, or—if you're willing—'The Gatekeeper of the Code Kingdom.'"
“代码王国?”小明瞪大了眼睛,“那是什么地方?”
"Code Kingdom?" Xiao Ming's eyes went wide. "What's that place?"
李老师在他旁边坐了下来,那台老旧的电脑椅发出吱呀一声抗议,却似乎一点都不介意这位老朋友的归来。“代码王国是一个神奇的地方,”李老师的声音低沉而富有磁性,“在那里,你可以用一种叫做'编程语言'的东西,和电脑进行对话。你可以告诉电脑帮你做作业、分析数据、制作游戏,甚至创造属于自己的虚拟世界。”
Teacher Li sat down beside him. The old computer chair let out a creaking protest but didn't seem to mind its old friend returning. "The Code Kingdom is a magical place," Teacher Li's voice was deep and magnetic. "There, using something called a 'programming language,' you can have conversations with computers. You can ask computers to help with your homework, analyze data, create games, even build your own virtual worlds."
小明的心跳开始加速。作为一个资深的游戏玩家,他做梦都想创造一款属于自己的游戏。而现在,一个创造世界的机会就摆在他面前。
Xiao Ming's heart began to race. As an avid gamer, he had dreamed of creating his own game. And now, an opportunity to create a world was right in front of him.
“但是,”李老师话锋一转,“想要进入代码王国,你首先需要学会一门语言。就像你要去英国需要学英语,去日本需要学日语一样,想要和电脑对话,你需要学会一门编程语言。”
"But," Teacher Li turned his attention, "to enter the Code Kingdom, you first need to learn a language. Just as you need to learn English to go to Britain or Japanese to go to Japan, to have conversations with computers, you need to learn a programming language."
“编程语言?是用编程的方式说话吗?”小明好奇地问。
"Programming language? Is that speaking in a programmed way?" Xiao Ming asked curiously.
李老师被他的理解逗笑了:“不是不是。编程语言是一种特殊的语言,它是专门设计出来让人类能够和电脑沟通的语言。你可以把编程语言想象成一座桥梁——一端是人类友好的表达方式,另一端是电脑能够理解的机器指令。”
Teacher Li laughed at his interpretation: "No, no. A programming language is a special kind of language, designed specifically to allow humans to communicate with computers. You can think of a programming language as a bridge—one end is human-friendly expressions, the other end is machine instructions that computers can understand."
小明若有所思地点点头。他想起了小时候搭积木的经历——那些五颜六色的塑料积木,看起来简单,却可以拼出城堡、汽车、飞机……而编程语言,就像是他和电脑之间的“积木”,只不过这些积木更加神奇,可以拼出任何他能够想象到的东西。
Xiao Ming nodded thoughtfully. He remembered his childhood experiences building with blocks—those colorful plastic building blocks that seemed simple but could be assembled into castles, cars, airplanes... And programming languages were like the "blocks" between him and the computer, except these blocks were far more magical and could be assembled into anything he could imagine.
“那我应该学什么编程语言呢?”小明急切地问。
"Then which programming language should I learn?" Xiao Ming asked eagerly.
李老师的眼中闪过一丝神秘的光芒:“这正是命运奇妙的地方。让你遇见这台电脑,让你看到那个闪烁的光标——现在,我要向你介绍一种叫做Python的编程语言。”
Teacher Li's eyes sparkled with a mysterious gleam: "This is precisely where fate works in mysterious ways. Having you discover this computer, having you see that blinking cursor—now, I want to introduce you to a programming language called Python."
“派森?”小明努力回忆着这个名字,“我好像在什么地方听过……”
"Pie-thon?" Xiao Ming tried to recall the name. "I think I've heard it somewhere before..."
“Python是一种非常特别的语言,”李老师开始解释,“它诞生于1991年,由一位名叫吉多·范罗苏姆的荷兰程序员创造。你知道Python这个词的意思吗?”
"Python is a very special language," Teacher Li began to explain. "It was created in 1991 by a Dutch programmer named Gui