Night 3: Talk to your pet
你已使用 Python 或伪代码完成过这个夜间练习,两种语言均计入完成记录。你可以再次练习。
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
今晚:和你的宠物说话
- 你的宠物有了名字。现在它想知道你的名字。
- 你将学习一件事:
input()。
今晚的词语
| 词 | 意义 |
|---|---|
| 输入 | 用户在程序中输入的内容 |
| 用户 | 使用程序的人 |
| 等待 | 停下来,什么也不做,直到某件事发生 |
input() 等待用户
input()使程序停止并等待。- 用户输入内容并按 Enter 键。
- 将答案保存在变量中。
print("What is your name?")
name = input()
print("Hello,", name)
- 点击运行。会打开一个框。输入你的名字并按 Enter 键。

答案始终是文本
input()始终给出文本,即使用户输入的是7。- 明天你会看到如何将文本转换为数字。
提问、等待、回答
- 许多程序按下面的方式工作:
- 1。用
print提问。 - 2。用
input()等待答案。 - 3。使用变量,通过
print回答。
print("What is your favourite food?")
food = input()
print("Yum!", food, "is great!")
现在轮到你
- 完成下面的任务。点击运行并输入答案。
- 然后点击检查答案。检查程序会为你输入一些答案。
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Your pet asks your name by printing What is your name?. Read it with input(). Then print Nice to meet you, and the name. For the name Sam, the greeting is Nice to meet you, Sam.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Your pet asks: What colour? Read the answer with input(). Then print I will paint my house and the colour. For blue, the last line is I will paint my house blue.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Read 二 answers with two input() lines: first a name, then a city. Then print one line like Sam lives in Ningbo.
点击“运行”查看此处输出。