Getting Input: Making a Program Talk Back

← Back to Blog & Articles

A program that always does the same thing gets boring quickly. Input lets it respond to the person using it.

The input function

In Python, input("What is your name? ") shows a question and waits for the user to type an answer. The answer can be saved in a variable:

name = input("What is your name? ")
print("Nice to meet you,", name)

Input is always text

Whatever the user types arrives as text, even if it looks like a number. To do math, convert it first with int() for whole numbers:

age = int(input("How old are you? "))
print("Next year you will be", age + 1)

Common mistakes

  • Forgetting to convert text to a number before adding.
  • Typing a word when the program expects a number, which causes an error.
  • Forgetting the space at the end of the question, which makes the answer run together with it.

Staying safe

When practicing, use invented names and details. A good habit is to never type real personal information into a program or an online tool.

Ideas to try

  • A program that asks for a favorite animal and a favorite color, then invents a creature name.
  • A tip calculator for a pretend restaurant.
  • A silly story where the user supplies the nouns and verbs.

Takeaway

Input turns a one-way program into a conversation, and learning to handle it correctly is a key step.

Continue with the book

Explore the full treatment, worked examples, and exercises in Code Quest with Python.


Adapted from Code Quest with Python, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top