Search⌘ K
AI Features

Handling User Input

Explore how to capture and process user input in Python using the input() function and type conversion methods like int() and float(). Understand turning user input from text into numbers to build interactive scripts, including a simple calculator. Gain skills to write flexible programs that handle dynamic data and prepare for decision-making with conditional logic.

Up until now, our programs have been one-sided conversations. We have mastered output using print() to display information to the console, but we have had no way to listen. Real-world software is conversational: it accepts data, processes it, and responds. In this lesson, we will learn the input side of the equation. By combining our existing knowledge of print() with the new input() function, we transform our scripts from static calculators into dynamic tools that adapt to the user.

Capturing user text

To make a program interactive, we need to pause execution and wait for the user to type something. Python provides the built-in input() function for this purpose. When Python encounters this function, it stops and waits for the user to type and press Enter. ...