Scratch ask and answer as input()

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Scratch ask and answer as input()

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which Python line matches the Scratch block: ask What is your name? and wait?
A name = input("What is your name? ")
B name = print("What is your name? ")
2. In Scratch, the answer reporter holds what the user typed. What does Python do instead?
A Stores the reply in a variable such as name
B Keeps the reply in a built-in word called answer
3. Where does the prompt text go in Python's input()?
A After the brackets: input() "Your name? "
B Inside the brackets, in quotes: input("Your name? ")
4. Which line stores the user's reply so it can be used later?
A age = input("How old are you? ")
B input("How old are you? ")
5. What happens when Python runs name = input("What is your name? ")?
A It saves the prompt text in name and carries on straight away
B It shows the prompt, waits for typing, then saves the reply in name

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1name = input("What is your name? ") AThe prompt text is missing quote marks, so Python thinks it is code instead of text. It should be input("What is your name?").
2print("Hi " + name) Bcolour = input("Favourite colour? ")
3The question that Scratch shows in ask and wait goes inside the brackets of input() as text in quotes CThe reply is never stored in a variable, so name does not exist. It should start with name = input(...).
4The Scratch answer reporter is only available until the next question, so Python stores the reply in a named variable to use later Dinput("How old are you? ")
5name = input(What is your name?) EShows the question, waits for the user to type a reply, and stores it in the variable name
6input("What is your name? ") print("Hi " + name) FUses the stored reply, like putting the Scratch answer reporter into a say block

Definitions

name = input("What is your name? ")

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
name = _____("What is your name? ")
2.
name = input("What is your name? ") print("Hi", ____)
3.
name _ input("What is your name? ")
4.
name = input("What is your name? ") _____("Hello", name)
5.
city = _____("Which city do you live in? ")

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A name = ask("Your name? ")
B print("Hello " + name)
C print("Nice to meet you!")
Question 2
A print("Welcome!")
B colour = input(Colour?)
C print("I like " + colour)
Question 3
A name = input("Name? ")
B age = input("Age? ")
C print(name, "is", Age)
Question 4
A print("Hi!")
B pet = input("Your pet? ")
C print("Cute " + "pet")
Question 5
A print("Say hi")
B answer == input("Reply? ")
C print("You said " + answer)

Answer Key

Scratch ask and answer as input()
Section A: Quick Questions
Q1
A — name = input("What is your name? ")
Q2
A — Stores the reply in a variable such as name
Q3
B — Inside the brackets, in quotes: input("Your name? ")
Q4
A — age = input("How old are you? ")
Q5
B — It shows the prompt, waits for typing, then saves the reply in name
Section B: Match the Pairs
Q1
name = input("What is your name? ") → Shows the question, waits for the user to type a reply, and stores it in the variable name
Q2
print("Hi " + name) → Uses the stored reply, like putting the Scratch answer reporter into a say block
Q3
The question that Scratch shows in ask and wait goes inside the brackets of input() as text in quotes → input("How old are you? ")
Q4
The Scratch answer reporter is only available until the next question, so Python stores the reply in a named variable to use later → colour = input("Favourite colour? ")
Q5
name = input(What is your name?) → The prompt text is missing quote marks, so Python thinks it is code instead of text. It should be input("What is your name?").
Q6
input("What is your name? ") print("Hi " + name) → The reply is never stored in a variable, so name does not exist. It should start with name = input(...).
Section C: Definitions
Q1
name = input("What is your name? ") — Like Scratch ask and wait: input() shows the prompt, waits for a reply, and the answer is stored in a variable (name), just like the answer reporter.
Section D: Fill in the Blanks
Q1
name = input("What is your name? ")
Q2
name = input("What is your name? ") print("Hi", name)
Q3
name = input("What is your name? ")
Q4
name = input("What is your name? ") print("Hello", name)
Q5
city = input("Which city do you live in? ")
Section E: Spot the Error
Q1
A — Python has no ask() function. The Scratch ask and wait block is written as input(), so the line should be name = input("Your name? ").
Q2
B — The prompt text inside input() is a string, so it needs quotes. It should be colour = input("Colour? ").
Q3
C — Variable names are case-sensitive. The answer was stored in age, not Age, so Python would give a NameError. It should be print(name, "is", age).
Q4
C — Putting quotes around pet makes it plain text, so it prints the word pet instead of the answer. Use the variable: print("Cute " + pet).
Q5
B — A double equals sign (==) compares two values. To store the reply in a variable, use a single equals sign: answer = input("Reply? ").