TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Python

Get User Input in Python 3.6

Python Tutorials

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

User Input in Python

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:

https://www.python.org

Related Posts

Download Python Windows 11

Python /

Download & Install Python on Windows 11

PyCharm CE

Python /

Install PyCharm on Ubuntu Linux

Python Install on CentOS Linux

Python /

Install Python on CentOS

What is Python?

Python /

What is Python?

Install Python

Python /

Install Python 3.6 on Windows

‹ Running a Python Script› Working with PyCharm IDE

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version