Night 15: Loud and quiet
你已使用 Python 或伪代码完成过这个夜间练习,两种语言均计入完成记录。你可以再次练习。
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Tonight: loud and quiet
- Welcome to week 3: words and secrets!
- Tonight your pet speaks loud and quiet.
- You will learn one thing: tools 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 |
English
Loud and quiet
- Put a dot and the tool name after the text.
word = "Hello"
print(word.upper())
print(word.lower())
print(word)
worditself does not change..upper()and.lower()give a new text.
English
Count the characters
lencounts the characters in a text. Spaces count too.
name = "Lumi"
print(len(name))
print(len("Good night"))
| Text | len |
|---|---|
"Kit" |
3 |
"Good night" |
10 |
"" |
0 |
English
Compare without worrying about capitals
- For Python,
"YES"and"yes"are different. - Make both lower case, then compare:
answer = "YES"
if answer.lower() == "yes":
print("OK!")
- Now make your pet shout and whisper!
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Your pet shouts! Read a word with input(). Print it in capital letters with ! after it. hello becomes HELLO!.
点击“运行”查看此处输出。
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Now your pet whispers. Read a word and print it in small letters. HELLO becomes hello.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Read a name. Print the name, has, the number of letters, and letters. For Kit the output is Kit has 3 letters.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Read two words. If they are the same word, even with different capitals (YES and yes), print Same!. Otherwise print Different.
点击“运行”查看此处输出。