Input is information a program or task receives before it does its work. Output is what it produces. For a minutes-to-hours converter, the minutes are input; the displayed hours and minutes are output. Identifying both before coding helps clarify the task. section 6.2 section 2.5
Input can reach a program in several ways:
- A value can be set in code, such as minutes_to_convert = 123. section 6.2
- A user can type a response when the program asks a question. section 11.2
- A program can read structured data from a file when entering many values one by one would be impractical. section 23.0
Ask for a number
user_input = input("Enter a number to find the square of: ") num = int(user_input) print(num * num) First, input() displays the prompt and waits for the user to press Enter. The response is stored in user_input as a string, even if the user typed digits. Next, int() converts that string to an integer. Finally, the program prints the square. Storing the response matters: asking a question but ignoring its answer cannot change the result. section 11.2
Input can also guide which code runs. A decision can select statements based on a user's response. Make expected responses clear: an adventure game, for example, announces that commands must be in capital letters and that other commands end the program. section 13.0 section 15.1
A function receives input through parameters. In a definition such as def get_word_length(word1, word2), the parameter names stand in for values not yet supplied. Calling the function with two strings gives those parameters values, in order, for that call. The function can then combine the strings and return their length. A docstring can state the expected parameter names and types, what the function does, and what it returns. section 21.1 section 21.2 section 21.3
Inputs deserve testing, not just collecting. Before writing a name-mashup program, for example, plan to try short and long names, names with odd and even lengths, and other combinations. Run the program with different inputs and compare its actual output with the expected output; debug and repeat when they differ. section 12.1 section 2.3













