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 שתי answers with two input() lines: first a name, then a city. Then print one line like Sam lives in Ningbo.
לחץ על הרץ כדי לראות את התוצא כאן.