Taking User Input in Python Language

How to Take User Input in Python

We can take user input in python using the console window or we can also create GUI using python.

To create GUI windows in Python we use a library or module called Tkinter.

To take user input in python using console window we use and built in function called:

input()

Example:

name = input(“Enter Name”)

# Here name is the variable where we want to store of the value which user will enter in the console screen.

“Enter Name” is an instruction to user.

input() function creates string values only.

Example :

name = input(\”Enter Name\”)

pwd = input(\”Enter Password\”)

if(name==\”Mohan\”):

            print(\”Welcome Mohan\”)

if(pwd==\”123\”):

            print(\”Your Password is correct\”)

else:

            print(\”You are not mohan\”)

Exercise : Create a program in python to calculate the area of a triangle.

a=float(input(\”enter a in cm\”))

b=float(input(\”enter b in cm\”))

c=float(input(\”enter c in cm\”))

s=(a+b+c)/2

print(\”area is \” ,(s*(s-a)*(s-b)*(s-c))**0.5, \”cm^3\”)

input()

Leave a Comment