Programming basics · GCSE · OCR J277 2.2.1, AQA 8525 3.2.7, Edexcel 1CP2 6.4.1 · about 12 min
Asking questions with input(), and why every answer is text.
[1 mark]What does the program do when it reaches name = input("Name? ")?
[1 mark]The user types 20 at far = input("How far? "). What is stored in far?
[1 mark]What does this program print?
far = "20" print(far * 3)
202020
far holds text, and multiplying text repeats it. This is what happens when an input answer is used without converting it.
[1 mark]Why leave a space at the end of the prompt, as in input("Name? ")?
[1 mark]Which of these are inputs to a program?
Tick every answer that is true.
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 = ...
The hint students can ask for: Ask for the name and keep it in a variable, then use that variable in what you print. Change the LED after the greeting.
from bugbot import *
connect()
name = input("What is your name? ")
print("Hello " + name + ", I am BugBot")
led("green")
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.