Night 2: Give your pet a name
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Tonight: give your pet a name
- Last night your pet woke up. Tonight it gets a name.
- You will learn one thing: variables.
Words for tonight
| Word | Meaning |
|---|---|
| variable | a box with a name; it keeps a value |
| value | what is inside the box, like "Lumi" or 7 |
| text | letters and words; we put text in quotes |
English
A box with a name
- Write the name, then
=, then the value. =means put into the box. It does not mean "equals" like in maths.
pet_name = "Lumi"
print(pet_name)
print(pet_name)has no quotes. So Python shows what is in the box.
English
Quotes or no quotes?
- With quotes, Python prints the word itself.
- Without quotes, Python looks for a box with that name.
pet_name = "Lumi"
print("pet_name")
print(pet_name)
English
Print two things
- Put a comma between things in
print. - Python adds one space between them.
pet_name = "Lumi"
print("Hello,", pet_name)
English
A new value
- You can put a new value in the same box.
- The old value is gone. The box keeps only the newest one.
mood = "sleepy"
mood = "happy"
print(mood)
English
Good names
- Use small letters. Use
_between words:pet_name,best_food. - No spaces. Do not start with a number.
Petandpetare different names.
English
Now you try
- Do the tasks below. Press Run, then Check answer.
- When all tasks pass, your pet knows its name.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Make a variable called pet_name. Store the text "Lumi" in it.
출력을 보려면 '실행'을 클릭하세요.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The variable pet_name is ready. Print My name is and the name on one line, so the output is My name is Lumi. Use the variable, not the word Lumi.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Your pet wants a new name. Change pet_name 부터 "Nova" on the empty line. Do not change the print line. The output should be Hi, I am Nova.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Make two variables: pet_name = "Kit" 및 food = "apples". Then print Kit likes apples using 두 가지 모두 variables.
출력을 보려면 '실행'을 클릭하세요.