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()

Ankit Srivastava is an IT trainer, technology educator, and digital skills mentor with expertise in programming, data analytics, AI, and software development. He has successfully trained thousands of learners, with more than 10,000 student enrollments on Udemy. His practical teaching approach empowers students and professionals to build in-demand technical skills. Colorstech channel where Ankit posts video tutorials has more than 8000 Subscribers.


