Night 4: Feed your pet
You already finished this night, in Python or pseudocode. It counts for both. Practise again if you like.
Tonight: feed your pet
- Your pet is hungry. It needs energy.
- You will learn one thing: numbers and maths.
Words for tonight
| Word | Meaning |
|---|---|
| number | like 3 or 2.5; no quotes |
| add | put numbers together: + |
| times | multiply: * (not x) |
Numbers have no quotes
5is a number. You can do maths with it."5"is text. It is just the symbol 5.&joins two pieces of text.
OUTPUT 2 + 3
OUTPUT "2" & "3"
- The first line shows
5. The second line shows23: it joins the text.

Maths signs
| Sign | Meaning | Example | Answer |
|---|---|---|---|
+ |
add | 7 + 2 |
9 |
- |
take away | 7 - 2 |
5 |
* |
times | 7 * 2 |
14 |
/ |
divide | 7 / 2 |
3.5 |
DIV |
how many whole times | 7 DIV 2 |
3 |
MOD |
what is left over | 7 MOD 2 |
1 |
Change a number in a box
- To add to a variable, use its old value on the right.
- The computer works out the right side first. Then it fills the box.
- A box for whole numbers has the type
INTEGER.
DECLARE Energy : INTEGER
Energy ← 3
Energy ← Energy + 2
OUTPUT Energy
Read a number
- Declare the box as
INTEGER. ThenINPUTkeeps a number, and you can do maths with it.
DECLARE Snacks : INTEGER
OUTPUT "How many snacks?"
INPUT Snacks
OUTPUT Snacks * 3
Now you try
- Do the tasks below. Press Run, then Check answer.
- Feed your pet well tonight.
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Your pet has Energy ← 3. A snack gives it 2 more. Add 2 to Energy, then output Energy. The output is 5.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Your pet eats Apples ← 4 apples each day. How many apples does it eat in 7 days? Put the answer in ApplesInWeek. Use * and the variable Apples. Then output ApplesInWeek. The output is 28.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
The user types how many snacks to give. Read it into Snacks with INPUT. Your pet starts with Energy ← 10. Each snack adds 3. Output the new energy. For 2 snacks, the output is 16.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 3/5 · 200 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
You have Cookies ← 17 cookies and Pets ← 5 pets. Put the cookies each pet gets in Each (a whole number, use DIV). Put the cookies left over in Left (use MOD). Output Each, then Left.
Nhấn Chạy để xem kết quả ở đây.