Night 5: Is your pet hungry?
You already finished this night, in Python or pseudocode. It counts for both. Practise again if you like.
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Tonight: help your pet decide
- Is your pet hungry or happy? It depends on its energy.
- You will learn one thing:
IFandELSE.
Words for tonight
| Word | Meaning |
|---|---|
| if | only when something is true |
| else | in all other cases |
| condition | a question with the answer TRUE or FALSE, like Energy < 5 |
English
IF asks a question
IFasks a question.THENgoes at the end of the same line.- When the answer is
TRUE, the lines below run. ENDIFcloses theIF. EveryIFneeds its ownENDIF.
DECLARE Energy : INTEGER
Energy ← 2
IF Energy < 5 THEN
OUTPUT "I am hungry"
ENDIF
OUTPUT "Bye!"
OUTPUT "Bye!"comes afterENDIF. It always runs.- Move the lines inside the
IFto the right (indent them). It helps people read your code.
English
ELSE is the other way
- The lines after
ELSErun when the answer isFALSE. - Only one of the two parts runs, never both.
DECLARE Energy : INTEGER
Energy ← 8
IF Energy < 5 THEN
OUTPUT "I am hungry"
ELSE
OUTPUT "I am happy"
ENDIF

English
Question signs
| Sign | Question | TRUE example |
|---|---|---|
< |
less than? | 3 < 5 |
> |
more than? | 9 > 5 |
= |
the same? | "moon" = "moon" |
<> |
different? | "sun" <> "moon" |
<= |
less than or the same? | 5 <= 5 |
English
← or =?
- The arrow
←puts a value in a box:Word ← "moon". - After
IF, one=asks a question:IF Word = "moon" THEN - Text must match exactly.
"Moon"and"moon"are different.
English
Now you try
- Do the tasks below. Press Run, then Check answer.
- Check that every
IFhasTHENon its line and anENDIFat the end.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Read the energy with INPUT Energy. If energy is less than 5, output I am hungry. Otherwise, output I am happy.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Your pet guards a door. Read a word with INPUT Word. If the word is moon, output Come in!. Otherwise, output Go away!.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Read the energy with INPUT Energy. Below 3: output Very hungry. Below 7: output OK. Otherwise: output Full of energy. Pseudocode has no ELSEIF, so put a second IF inside the ELSE.
출력을 보려면 '실행'을 클릭하세요.