Skip to main content

Accepting user input in python

Accepting user input in python

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:

Accepting user input in python

The program is waiting for you enter your username, and it does nothing until the keyboard input is received. Let’s type in kelvin

Accepting user input in python

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

Accepting user input in python

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

Popular posts from this blog

Introduction to flask

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session because we are entering into one of python’s web-based application called flask. In this article, we are going to see the following What is flask Prequistes Installation of flask in python Some of flask template engine. What is flask? Flask is one of python-based framework which is used to create web applications. Flight is a very light web framework. During installation, flask comes with pre-installed modules and functions which are used to backup your own web applications. Flask is very easy to understand and perfect go-to for beginners and with flask, a web server can run in less than 3 lines of code. Prequistes Before learning flask, we recommend the reader to have a basic mastery of python concepts. Installation of flask  Before installing flask, we have to checked if python has been installed or. If n...

How to generate random numbers using NumP1

Hello. Welcome to another edition on this platform. For more better understanding, do checkout our YouTube channel to get the video tutorial. In this article of today, we are going to see how to generate random numbers using any of the following methods: Generating a random number Generating a random float and integer Generating random number arrays Generating random number from an array What is a random number? This is a number which cannot be predicted before its occurrence. This number might not different every time. Programmatically, they are two categories of random numbers:     Pseudo-Random numbers       True Random numbers. Just as programs which are written by programmers are a set of instructions, we must follow an algorithm to generate random numbers. Random numbers which are generated using an algorithm are called Pseudo-Random numbers. To generate a true random number, it is important to get the data from sources such as the keyboards, mou...

Introduction to Django

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session. we are entering into one of python’s application called Django. In this article, we are going to discuss the following: What is Django Why must we use Django  A brief history of Django Installation of Django Popularity of Django What is Django? Python has so many framework application and Django happen to be one of them. Being a python-based-framework, it is used to quickly create web applications.  When building websites, django provides similar ready-made components to handle user authentication, forms, a way to upload components. Why use django? Django is very fast. It takes applications from concept to applications very quickly Django has thousand available packages in it when it is installed. With django, we can launch web applications is a matter of hours. Django is a highly is secured and helps...