Night 16: Name tags
你已使用 Python 或伪代码完成过这个夜间练习,两种语言均计入完成记录。你可以再次练习。
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Tonight: name tags
- Your pet wants a name tag. Tonight you build text from pieces.
- You will learn one thing: joining text with
&.
Words for tonight
| Word | Meaning |
|---|---|
| join | put two pieces together into one |
| convert | change a value into another type |
| space | the empty character between words |
English
Join text with &
&puts two STRINGs together into one STRING.
DECLARE Name, Tag : STRING
Name ← "Kit"
Tag ← "Hello, " & Name & "!"
OUTPUT Tag
&adds no spaces. Write each space inside the quotes.

English
Numbers must become text first
&joins STRINGs only. Turn a number into a STRING withNUM_TO_STR.
DECLARE Age : INTEGER
Age ← 2
OUTPUT "Kit is " & NUM_TO_STR(Age) & " years old"
OUTPUT "Next year: " & NUM_TO_STR(Age + 1)
English
Commas or &?
| Code | What it does |
|---|---|
OUTPUT "Age: ", Age |
outputs the two values one after the other |
"Age: " & NUM_TO_STR(Age) |
makes one STRING you can store |
- Use commas to output quickly. Use
&when you need the text in a variable. - Now make some name tags!
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Read a name, then an age. Join the text with & to output Kit is 2 years old. Use NUM_TO_STR for the age.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Read a snack and a price. Put a price tag like apple: 3 coins in the STRING Tag, then output Tag.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Read a name and an age. Output Next year Kit is 3. Work out Age + 1 inside NUM_TO_STR.
点击“运行”查看此处输出。
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
Read a name, a kind and a number of nights. Output a 3-line card: Name: Kit, then Kind: fox, then Nights: 12/30.
点击“运行”查看此处输出。