DoAssignment study guide

B2.3 · Write keyboard input and screen output

Learn to write keyboard input and screen output through clear examples and targeted practice.

Ontario Grade 10 Computer Science

Introduction to Programming

A beginner’s guide to writing simple programs that communicate with a user

A program can communicate with a person by asking for information and showing a response. For example, a classroom program might ask for a student’s name and then display a greeting. The person types using the keyboard; the program handles the information; the screen shows the result. These are input, process, and output. This lesson focuses on writing keyboard input and screen output, as named in Ontario Grade 10 Computer Studies expectation B2.3. The Python 3 examples are short illustrations; the programming language used in your classroom may differ. The code is shown as text and has not been run.

What you will learn

  • Explain how keyboard input, processing, and screen output work together.
  • Write a short Python 3 program that asks for keyboard input and displays a useful response.
  • Trace example input through a program to predict its screen output.

1. Input, process, and output

Input is information supplied to a program. In this lesson, the user supplies input by typing on a keyboard. A prompt is a message the program displays to tell the user what to type. The prompt helps the user understand what information is being requested.
Processing is what the program does with the information it receives. For a greeting program, processing can simply mean using the typed name to prepare a greeting. Processing does not have to be complicated: the program may just choose what words to display.
Output is information the program displays for the user, such as a prompt or a completed greeting. In Python 3, input() asks for keyboard input and print() displays output on the screen. A program can use print() to show a prompt before it requests input.
Think of the three parts as a short sequence: the user types information, the program handles it, and the program displays a result. A diagram can help keep the roles clear: the keyboard supplies the input, the program processes it, and the screen presents the output.
  • Input: information typed by the user.
  • Process: the program’s handling of that information.
  • Output: information displayed on the screen.

2. Writing and tracing a simple exchange

In Python 3, input("What is your name? ") displays the question and waits for the user to type. When the user presses Enter, the typed response becomes the result of the input() instruction. The program can then use that response in a later instruction.
The text inside the quotation marks is the prompt. The user’s typed response is not part of the code: it is supplied while the program is being used. The prompt and the final message are both screen output, while the typed name is keyboard input.
A trace is a written account of how a particular input leads to output. Tracing a small example means following the instructions in order and substituting the stated user response where input is requested. This lets you check what a program is intended to display without claiming that the code has been run.
When writing a program, make each prompt clear and make the response fit the information requested. For example, ask for a name if the program will display a greeting. A polite, direct prompt is easier to answer than a vague message.
  • input() requests keyboard input and displays its prompt.
  • print() displays a message on the screen.
  • A trace follows the program using a stated example response.

3. Clear prompts, useful output, and careful checking

A short program should guide the user from the first message to the final result. Before asking for input, decide what the user needs to know. After receiving input, decide what response would make the result understandable. This is especially useful when someone else may use your program.
For example, a program asking for a favourite book should use a prompt that says what to type. Its response can repeat the book title in a sentence so the user can tell how the input was used. The program does not need to judge the answer; it can simply display it.
Check a program by tracing a specific response. Ask: What appears before the user types? What does the user type? What appears after Enter? If any message is unclear, revise the prompt or output. This is a way to reason about the written code, not a claim that it has been executed.
Be considerate about what you ask someone to type. In a classroom greeting example, a first name is enough; there is no need to request private details that the program does not need. Clear prompts also help users who are unfamiliar with the activity understand what to do.
  • Ask only for information the program needs.
  • Use prompts that tell the user what to enter.
  • Trace an example response to check that the displayed messages make sense.

Trace of the name greeting example

Program momentWhat happensScreen message or typed response
Before typingThe program requests a nameWhat is your name?
User inputThe user types a responseMaya
After typingThe program displays a greetingHello, Maya!

Worked example

Ask for a name and display a greeting

Write a program that asks for a name and displays a greeting. Trace the example response Maya.
Name greeting: input to output
namemessagesKeyboard: typed nameProgram: prepare greetinScreen: prompt and greet

The keyboard supplies a name to the program, which displays a greeting on the screen.

Python 3

name = input("What is your name? ")
print("Hello,", name + "!")
  1. Request input
    The input() instruction displays a prompt and waits for the user to type a name. In this trace, the user types Maya and presses Enter.
  2. Display output
    The print() instruction uses the response to display a greeting. The expected screen messages are shown as a trace; this is not a claim that the code was run.
Answer: With the example response Maya, the expected prompt is “What is your name?” and the expected output is “Hello, Maya!”.
Check: The typed name is input. The greeting is output. The program uses the response to form the message.

Worked example

Ask for a favourite book

Write a program that asks which book the user likes and displays the title in a sentence. Trace the example response The Blue Door.
Book response: input to output
book titlemessagesKeyboard: book titleProgram: prepare sentencScreen: prompt and sente

A typed book title passes to the program and appears in a screen message.

Python 3

book = input("Name a book you like: ")
print("You like", book + ".")
  1. Ask a clear question
    The prompt tells the user what kind of response to type. The user enters The Blue Door and presses Enter.
  2. Display a sentence
    The program places the typed title into a sentence. The expected output shown here follows from the stated input; the code has not been run.
Answer: For the stated response, the expected prompt is “Name a book you like:” and the expected output is “You like The Blue Door.”
Check: The book title is keyboard input. Using it in the sentence is processing. Displaying the sentence is screen output.

Worked example

Ask for a snack and respond

Write a program that asks for a snack and displays a message that includes the response. Trace the example response apple slices.
Snack response: input to output
snackmessagesKeyboard: snackProgram: prepare responsScreen: prompt and respo

The user types a snack on the keyboard; the program prepares and displays a sentence.

Python 3

snack = input("What snack would you choose? ")
print("You chose", snack + ".")
  1. Receive the response
    The input() instruction displays a prompt. For this trace, the user types apple slices and presses Enter.
  2. Show a useful message
    The print() instruction displays a response that includes the typed snack. This expected trace is worked out from the code rather than reported as an execution.
Answer: For the example response, the expected prompt is “What snack would you choose?” and the expected output is “You chose apple slices.”
Check: The prompt requests one piece of information, and the final output uses the response. The program does not need to request private information for this task.

Common mistakes and how to avoid them

Thinking the prompt is the user’s input.
Correction: The prompt is a message displayed by the program. The input is what the user types in response.
Using print() when the program needs to wait for a typed response.
Correction: Use input() to request keyboard input. Use print() to display a message.
Writing a prompt that does not say what information is needed.
Correction: Make the prompt specific, such as “Name a book you like:” rather than “Enter something:”.
Claiming a code example was tested when it was only read or traced.
Correction: Describe the result as the expected output for the stated input unless the program was actually run.

Lesson summary

  • Keyboard input is information a user types in response to a program.
  • Processing is how the program uses the information it receives.
  • Screen output includes prompts and the program’s displayed response.
  • In Python 3, input() requests keyboard input and print() displays output.
  • Trace a stated response through the instructions to predict the expected screen messages.

Check your understanding

Question 1

A program displays “Enter your name:” and waits. Which part is the user’s input?
  1. The words “Enter your name:”
  2. The name the user types
  3. The screen itself
  4. correctIndex
Show answer and explanation
The name the user types
The displayed words are the prompt. The name typed by the user is keyboard input.

Question 2

In Python 3, which instruction is used to display a message on the screen?
  1. print()
  2. input()
  3. The user’s typed response
  4. correctIndex
Show answer and explanation
print()
print() displays output. input() requests a response from the keyboard.

Question 3

A program asks “What snack would you choose?” The user types “apple slices,” and the program displays “You chose apple slices.” Which item is output?
  1. The typed words “apple slices”
  2. The displayed sentence “You chose apple slices.”
  3. The keyboard
  4. correctIndex
Show answer and explanation
The displayed sentence “You chose apple slices.”
Output is the information the program displays on the screen.

Key terms

Input
Information supplied to a program, such as words typed on a keyboard.
Process
The program’s handling of the input.
Output
Information displayed by a program, such as a prompt or response.
Prompt
A message that asks or guides the user to provide information.
Trace
A written account of what a program is expected to do for a stated input.

Continue through ICS2O

View the complete ICS2O Ontario Grade 10 Computer Science curriculum and lessons

Tutor support for B2.3 · Write keyboard input and screen output

Working on B2.3 · Write keyboard input and screen output in ICS2O? Bring the question and your own attempt. In a live session, you can point to evidence in the text, explain how it supports your claim, and revise one sentence together. Ask about the first step that does not make sense, then try a similar question yourself.

Explore coding tutoring · Request an eligible free 30-minute introduction. Your request is matched by subject and language; a tutor must accept before a time is confirmed.

برای مبحث B2.3 · نوشتن ورودی صفحه‌کلید و خروجی نمایشگر در درس ICS2O، سؤال و تلاش خود را همراه بیاورید. در جلسه می‌توانید شواهد متن را نشان دهید، ارتباط آن را با ادعای خود توضیح دهید و یک جمله را با هم بازنویسی کنید. راهنمای معلم برنامه‌نویسی را ببینید یا جلسهٔ معارفهٔ رایگان ۳۰ دقیقه‌ای درخواست کنید. زمان جلسه پس از پذیرش معلم قطعی می‌شود.

About this lesson and its review

Published by DoAssignment. This reviewed lesson follows Ontario Grade 10 Computer Science (ICS2O), expectation B2.3. It is a study resource, not an official curriculum publication.

Before publication, content is checked for structure, mathematical or chemical notation, calculations, course boundaries, and readability. Errors can still occur, so corrections are welcomed.

Official curriculum reference

Report a correction or ask a question