USER INPUT IN PYTHON

Python Free Tutorial

In our previous tutorial, we learned how to print messages as output and indentation rules. In this tutorial, we will learn how receive input from the user.

To obtain data or to send any results, developers must communicate with the user. For this reason, Python provides two built-in function to get / read the user data which is slightly different from other programming language because most of the programming language use a dialog box as a way to ask the user to provide some sort of feedbacks.

>>> x = input("enter anything")

input ( ) function takes user input and then evaluates the expression which means Python determines automatically if user has entered a string or a number or a list. By default, data from user is stored as string. Let’s take an example :

We assign data types to the user input variable introducing int, float, str and so on before input function. See more >>

Problem

We are going to write a small program that asks user’s name and then we’re going to print for that user with specific greeting messages.

Both these input () and print () are the built-in functions in Python. For the above mentioned questions we are going to call the input function and in between parentheses we are going to add a command which gets printed on the terminal and gives instruction to the user. So, these these text inside parentheses print message on the terminal and and it will wait for the user to enter a value. Whatever the user enters in this input function , is temporarily store in the memory using a variable, for our case name is the variable.

Let’s extend above program and ask two questions. First, person name and secondly their favourite programming language. And then print a message in the pattern like ABC likes Python.

See more about declaring variables in our next article : Click Here >

EXAMPLES

1 Find Simple intrest using ( SI = P*T*R /100)

2 Find area of rectangle

This page is contributed by Diwas & Sunil . If you like AIHUB and would like to contribute, you can also write an article & mail your article to  itsaihub@gmail.com . See your articles appearing on AI HUB platform and help other AI Enthusiast.

About Diwas

🚀 I'm Diwas Pandey, a Computer Engineer with an unyielding passion for Artificial Intelligence, currently pursuing a Master's in Computer Science at Washington State University, USA. As a dedicated blogger at AIHUBPROJECTS.COM, I share insights into the cutting-edge developments in AI, and as a Freelancer, I leverage my technical expertise to craft innovative solutions. Join me in bridging the gap between technology and healthcare as we shape a brighter future together! 🌍🤖🔬

View all posts by Diwas →

4 Comments on “USER INPUT IN PYTHON”

  1. Hey There. I discovered your weblog the use of msn. That is a really neatly written article.
    I’ll make sure to bookmark it and return to learn more of your useful
    info. Thanks for the post. I’ll certainly return.

Leave a Reply

Your email address will not be published. Required fields are marked *