Night 3: Talk to your pet
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Tonight: talk to your pet
- Your pet has a name. Now it wants to know your name.
- You will learn one thing:
input().
Words for tonight
| Word | Meaning |
|---|---|
| input | what the user types into the program |
| user | the person who uses the program |
| wait | stop and do nothing until something happens |
English
input() waits for the user
input()stops the program and waits.- The user types something and presses Enter.
- Keep the answer in a variable.
print("What is your name?")
name = input()
print("Hello,", name)
- Press Run. A box opens. Type your name and press Enter.
English
The answer is always text
input()always gives you text, even if the user types7.- Tomorrow you will see how to turn text into a number.
English
Ask, wait, answer
- Many programs work like this:
-
- Ask a question with
print.
- Ask a question with
-
- Wait for the answer with
input().
- Wait for the answer with
-
- Answer with
print, using the variable.
- Answer with
print("What is your favourite food?")
food = input()
print("Yum!", food, "is great!")
English
Now you try
- Do the tasks below. Press Run and type an answer.
- Then press Check answer. The checker types some answers for you.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Your pet asks your name. Read it with input(). Then print Nice to meet you, and the name. For the name Sam, the output is Nice to meet you, Sam.
実行ボタンをクリックして出力を確認してください。
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Your pet asks: What colour? Read the answer with input(). Then print I will paint my house and the colour. For blue, the last line is I will paint my house blue.
実行ボタンをクリックして出力を確認してください。
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Read 2つ answers with two input() lines: first a name, then a city. Then print one line like Sam lives in Ningbo.
実行ボタンをクリックして出力を確認してください。