liveBook · Manning

Input()

As explained in Python Workout: 50 ten-minute exercises

input is a Python built-in function that displays a prompt and returns the user's response as a string.

input() displays a prompt and returns whatever the user enters as a string. Use the prompt to collect data, then convert that string when the program needs a number or another type. section 1.2 section 1.3

A practical input workflow is:

  • Display a clear prompt, such as input('Enter your name: '). section 1.2
  • Convert numeric input explicitly: int() for integers or float() for floating-point values. section 1.3 section 1.13
  • Handle invalid numeric responses with try and except ValueError. section 1.13
  • Remember that pressing Enter returns an empty string, which behaves as False in a conditional. section 1.13

Validated numeric input

try: n = float(input('Enter a number: ')) print(f'n = {n}') except ValueError: print("That's not a valid number!") section 1.13

name = input('Enter your name: ')
print(f'Hello, {name}!')

A minimal prompt-and-response pattern combines input() with an f-string. section 1.2

How Python Workout: 50 ten-minute exercises covers it

How deep it goes
Defines prompting and string return behavior, then develops conversion, empty-input handling, and validation without covering implementation internals.
Examples
Uses a greeting, a number-guessing game, repeated thought prompts, and validated floating-point entry.
What it assumes
Assumes basic Python functions and conditionals while teaching that input returns strings and requires explicit conversion.
What you can do after
Apply it via Python prompts, convert responses for computation, and reject invalid numeric input.
How it connects
Connects user input with type conversion, loops, conditionals, exception handling, and truthiness.

Also explained in

Compare how 7 books explain input() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Workout: 50 ten-minute exercises. The section links point to the parts of the book it draws on.