In this tutorial, we will learn to get user input in Python. We can get user input by using the input() Function. Let us see a simple program.
name = input(“Enter your name: “)
The left side of the assignment statement is the variable name that holds a value whatever the user enters. On the right side, is a call to the function input(). The task of input() function is to wait and get the text user enters. The function will wait until the user hits the enter key. As you notice, we have passed an argument to the input function “Enter your name: “. The function uses this string to prompt to the user. Good programs use meaningful text that conveys the message to the user. Choose a meaningful text message in your program.
name = input(“Enter a number between 1 and 100: “)
name = input(“number”)
input() functions wait for the user to enter some text. Once the user presses the Enter key input() returns whatever the user typed to the variable name.
#Python program to demonstrate user input #main function def main(): a=input("Enter an integer a : ") b=input("Enter an integer b : ") total=add(a,b) print(total) #add function def add(a,b): return int(a) + int(b) main()
Python Tutorial on this website can be found at:
More information on Python is available at the official website: