Hi guys. Welcome to another amazing tutorials on python. If you are new in this platform and haven’t checked out previous tutorials, please do checkout our previous tutorials on python and other programming languages and subscribe to our YouTube channel for the video tutorials. To get more of our content, you can check out our Facebook group and page. We also offer training for developers.
In this article we are going to see how to create sentences and other outputs by just inputting information into a program.
We all might have used user’s input to work knowingly or unknowingly. Input can come from a variety of sources such as keyboard, mouse clicks, the internet, database, or external storage. The keyboard is the most commonly used channel. The input from the keyboard is read using the input() built-in function. The input from the user is read as a prompt string and is being stored as a variable
Syntax
input(prompt)
Once the function is called, the prompt string is displayed onscreen as the program awaits user’s input. Python returns the user’s response as a string.
Below is a simple illustration, here is a program that collects keyboard input for the username, and age:
username = input("Enter username:")
age = input("Enter your age:")
print("Good day" + username + "! you are " + age)
When you run the program, the first prompt string that will appear on the screen is:
The program is waiting for you enter your username, and it does nothing until the keyboard input is received. Let’s type in kelvin
after this name has type, the program will then proceed to the next command or prompt string.
Let’s type in the age 28
After the programs execution, this is what you will see as your results
Take note that when writing your own program, make sure to provide appropriate white spaces so as to allow easy readability. You wouldn’t want the user’s input to crowd the prompt string so you have to provide a space before the closing quotation mark.
we have come to the end of this session. Hope you enjoyed the tutorial. Have a time coding guys.
Comments
Post a Comment
Please do not enter any spam link in the comment box.