Night 21: Secret messages
이미 Python 또는 의사 코드로 이날의 학습을 마쳤습니다. 두 언어 모두에서 완료한 것으로 인정됩니다. 원하면 다시 연습하세요.
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Tonight: secret messages
- Your pet wants to send secret messages to its friends.
- Tonight's project: a secret code. You use loops over text and one new idea: character codes.
Words for tonight
| Word | Meaning |
|---|---|
| secret | something only some people may know |
| code | a number for each character; also a way to hide a message |
| shift | move along by some places |
English
Every character has a number
- The computer keeps each character as a number.
ordgives the number.chrgives the character back.
print(ord("a"))
print(ord("b"))
print(chr(99))
| Character | a |
b |
c |
… | z |
|---|---|---|---|---|---|
| Code | 97 | 98 | 99 | … | 122 |
English
Move a letter on
- Number, plus 1, back to a character:
letter = "k"
code = ord(letter)
print(chr(code + 1))

English
Hide a whole word
- Do it for every letter in a loop:
word = "cat"
secret = ""
for letter in word:
secret = secret + chr(ord(letter) + 1)
print(secret)
- To read the message, your friend moves each letter back by one:
- 1.
English
Week 3 is done!
- You can change text, build it, loop through it, and keep facts in dictionaries.
- Try a shift of 3 instead of 1. Send a secret message to a friend!
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Every character has a number code. Print the code of "a" with ord, then the character with code 98 with chr. The output is 97, then b.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Read one letter. Print the 차선 letter: a gives b, k gives l. (No z tonight.)
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Read a word. Move every letter on by one, and print the secret word. cat gives dbu.
출력을 보려면 '실행'을 클릭하세요.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
Make z go back to a. Read a small-letter word and move each letter on by one, so zoo gives app. Use % 26.
출력을 보려면 '실행'을 클릭하세요.