The answersDownload the PDF
Worksheet

F1.7 Input from the user

Programming basics · GCSE · OCR J277 2.2.1, AQA 8525 3.2.7, Edexcel 1CP2 6.4.1 · about 12 min

BugBotLab
NameClassDate

What this lesson is about

Asking questions with input(), and why every answer is text.

Questions 5 marks in all

  1. [1 mark]What does the program do when it reaches name = input("Name? ")?

    1. AShows the prompt and waits for the user to type and press Enter
    2. BCarries on and fills in name later
    3. CPrints the value of name
    4. DAsks the robot for its name
  2. [1 mark]The user types 20 at far = input("How far? "). What is stored in far?

    1. AThe string "20"
    2. BThe integer 20
    3. CThe real number 20.0
    4. DNothing until it is printed
  3. [1 mark]What does this program print?

    far = "20"
    print(far * 3)
  4. [1 mark]Why leave a space at the end of the prompt, as in input("Name? ")?

    1. ASo the answer is not squashed against the question
    2. BPython needs it to work
    3. CIt makes the answer a string
    4. DIt stops the robot
  5. [1 mark]Which of these are inputs to a program?

    Tick every answer that is true.

    1. AA name typed at the keyboard
    2. BA distance reading from a sensor
    3. CText printed to the screen
    4. DA note played on the buzzer

The task: greet by name

Ask What is your name? , then print Hello <name>, I am BugBot using the answer, and turn the LED green. The task will answer Ada, but your program must work for any name, so do not type Ada into it.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

name = ...

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/f1-7-input/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Ask for a colour and a second colour, and flash the LED between them three times.
  2. Ask the user's name, then print it five times on one line using *.
  3. What happens if you just press Enter without typing anything? What does input give back?