Night 15: Loud and quiet
คุณเรียนจบคืนนี้แล้วด้วย Python หรือรหัสเทียม และนับรวมในทั้งสองภาษา คุณสามารถฝึกอีกครั้งได้ตามต้องการ
Tonight: loud and quiet
- Welcome to week 3: words and secrets!
- Tonight your pet speaks loud and quiet.
- You will learn one thing: functions for text.
Words for tonight
| Word | Meaning |
|---|---|
| upper case | capital letters: A B C |
| lower case | small letters: a b c |
| length | how many characters are in a text |
Loud and quiet
TO_UPPERandTO_LOWERtake a text and give a new text back.
DECLARE Word : STRING
Word ← "Hello"
OUTPUT TO_UPPER(Word)
OUTPUT TO_LOWER(Word)
OUTPUT Word
Worditself does not change.- 9618 also has
UCASEandLCASE, but they take one character. For a whole word, useTO_UPPERandTO_LOWER.
Count the characters
LENGTHcounts the characters in a text. Spaces count too.
DECLARE Name : STRING
Name ← "Lumi"
OUTPUT LENGTH(Name)
OUTPUT LENGTH("Good night")
| Text | LENGTH |
|---|---|
"Kit" |
3 |
"Good night" |
10 |
"" |
0 |
Compare without worrying about capitals
- In pseudocode,
"YES"and"yes"are different. - Make both lower case, then compare:
DECLARE Answer : STRING
Answer ← "YES"
IF TO_LOWER(Answer) = "yes" THEN
OUTPUT "OK!"
ENDIF
- Now make your pet shout and whisper!
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Your pet shouts! Read a word with INPUT Word. Output it in capital letters with ! after it. hello becomes HELLO!.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Now your pet whispers. Read a word and output it in small letters. HELLO becomes hello.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Read a name. Output the name, has, the number of letters, and letters. For Kit the output is Kit has 3 letters.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Read two words. If they are the same word, even with different capitals (YES และ yes), output Same!. Otherwise output Different.
คลิก Run เพื่อดูผลลัพธ์ที่นี่