In my last article I discussed how to use the Input-Process-Output template as a general guide to how programs should be structured in Python. To review, most Python programs will consist of three steps — getting input into the program, processing the input in some way, and outputting the results of the processing.

In this article, I’m going to focus on one part of that step — getting input into a program — by prompting the user to enter some data and then reading the data into the program. This is a mostly straightforward process except for some data conversions that have to occur when you are inputting numbers.

Defining a Prompt

Let’s start by defining the word prompt. A prompt is a message to the user of your program telling them what they are supposed to be entering into the program. A prompt needs to be descriptive but doesn’t have to be overly detailed.

For example, if your program needs the user to enter their name, you can use a prompt like this:

Enter your name:

However, you may need to be more specific if you want the user to enter their first name and their last name separately. The more appropriate prompt in this case might really be two prompts:

Enter your first name:
Enter your last name:

#learn-to-code #learn-python-programming #python #learning-python #python-programming

Learning Python: The Prompt, Then Read Template
3.15 GEEK