Night 18: Your pet's ID card
今夜の課題はPythonまたは疑似コードですでに完了しています。両方の言語で完了として記録されます。よければもう一度練習してください。
Tonight: your pet's ID card
- Your pet needs an ID card with its name, age and food.
- You will learn one thing: records.
Words for tonight
| Word | Meaning |
|---|---|
| record | one card that keeps several facts together |
| field | one fact on the card, like Age |
| type | the plan: which fields every card has |
Plan the card with TYPE
TYPE…ENDTYPEsays which fields the card has. Each field has a name and a type.- Then
DECLAREa variable of that type: a real card.
TYPE PetRecord
DECLARE Name : STRING
DECLARE Age : INTEGER
DECLARE Food : STRING
ENDTYPE
DECLARE Pet : PetRecord
Pet.Name ← "Kit"
Pet.Age ← 2
Pet.Food ← "fish"
OUTPUT Pet.Name, " eats ", Pet.Food

Use a field with a dot
Pet.Agemeans: theAgefield ofPet. It works like a variable.
TYPE PetRecord
DECLARE Name : STRING
DECLARE Age : INTEGER
ENDTYPE
DECLARE Pet : PetRecord
Pet.Name ← "Kit"
Pet.Age ← 2
Pet.Age ← Pet.Age + 1
OUTPUT Pet.Name, " is now ", Pet.Age
Common mistakes
| Wrong | Right | Why |
|---|---|---|
PetRecord.Name ← "Kit" |
Pet.Name ← "Kit" |
the type is only the plan; store in the variable |
OUTPUT Pet |
OUTPUT Pet.Name |
output one field at a time |
forget ENDTYPE |
ENDTYPE after the fields |
only DECLARE lines go inside the type |
- Now make your pet's ID card!
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Define a record type PetRecord with three fields: Name : STRING, Age : INTEGER, Food : STRING. Declare Pet : PetRecord, store Kit, 2 かつ fish, and output Pet.Name.
実行ボタンをクリックして出力を確認してください。
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
It is Kit's birthday! Add 1 to Pet.Age. Then output the new age: 3.
実行ボタンをクリックして出力を確認してください。
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Kit has a new toy. Add a field Toy : STRING to the type, store ball in it, and output Kit plays with ball using the fields.
実行ボタンをクリックして出力を確認してください。
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Read a field name with INPUT. Use CASE OF to output that field: name, age または food. For anything else, output No such thing.
実行ボタンをクリックして出力を確認してください。