Get User Input in Python 3.6
Introduction
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.
input() function
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.
Good
name = input(“Enter a number between 1 and 100: “)
Bad
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.
Screenshot
Code Listing
#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:
https://www.testingdocs.com/python-tutorials/
More information on Python is available at the official website: