编程语言趣味课堂-1

英语杂志 发布于 2025-09-24 02:00 小熊
333 0 0 30

🌟 Teacher Xiong's Programming Class - Lesson 1

Topic: Exploring "Addition" and Data Types in Python (初探 Python 中的「加法」与数据类型)


🕒 Class Start: A Warm-Up Question (课堂开始:热身小问题)

Teacher Xiong: Good afternoon, everyone! Today we’ll start with a simple problem—what’s 1 plus(加) 1?

Wang Wuhao: Teacher, are you looking down on(小看) us? 1 plus 1 is definitely 2!

Li Han: Exactly! Even elementary(初级的) school students know that.

Wang Wuhao: But… I have a feeling(感觉) it’s not that simple.

Ye Daining: Could it be "1 minus 1 equals 3"? Hahaha! I’m such a good boy a genius(天才)!

Jiang Chenyi: Let’s stop guessing, everyone. In my opinion(依我看来), this question is probably trickier than it seems.


🖥️ Hands-On Code: First Doubt (代码实操:第一个小疑问)

Teacher Xiong: Since you have doubts(疑问), let’s look at code directly—what happens if I run print('1+1')?

Cheng Chen: It must be 2! Teacher, are you still half-asleep(半睡 没睡醒)?

Wang Wuhao: No, there’s a detail here! Without the English quotation marks(引号), print(1+1) would give 2. But with the quotation marks, '1+1' becomes a string, so the output should be the characters 1+1 themselves(本身).

Jiang Chenyi: That’s right. I agree with(同意) Wang Wuhao.

Ye Daining: I get it too! Quotation marks are so important(重要的) here~

Cheng Chen: Oh! So that’s how it works! I totally understand(理解) now!


⚠️ Advanced Challenge: What to Do When an Error Occurs? (进阶挑战:遇到报错怎么办?)

Teacher Xiong: Great job!(很好) You all now know the difference between print('1+1') (outputs a string) and print(1+1) (outputs the calculation result 2). Now, let’s step it up—what will print(1+'1') give?

Qian Yuze: Huh? What kind of operation(操作) is this?

Bao Youting: Step aside(靠边站), everyone—I’m about to show off(展示) my skills… Wait, actually(其实), I don’t know either(同样 也). Hehe~

Li Han: Stop guessing! Let’s just open PyCharm and test it out(尝试出来)!

Wang Wuhao: Teacher, I tried it, and it reported an error right away! The error message(信息) is:

TypeError: unsupported operand type(s) for +: 'int' and 'str'

Teacher Xiong: Exactly. The error(错误) Wang Wuhao mentioned(注意) is exactly(确实) because of(因为) this line of code.

Zhang Zihao: Teacher, I can’t understand(懂) English. It’s so frustrating(气死我了)!

Wang Wuhao: I get it now. The error happens because the data types are different—you can’t add(加) them directly. One is an int (integer) type, and the other is a str (string) type.

Teacher Xiong: That’s correct. Congratulations(恭喜), Wang Wuhao—you guessed it right!

Everyone: Hahaha(哈哈哈哈哈)!

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
none
暂无评论...