Python input from user:
Python allows user for Input
python get input from user
A method to take input from user in python is totally different than the other programing language like c , c+ + and java, there is inbuild function in Python for input
Python 3.6 = input() // Latest version
Python 2.7 =raw input() // old version
Before Using input function console should tell user here you have to write the input this is very important step because one a programmer forgot this step console will wait for user input and user don't know where to write the input , this can be done by using print () function or writing a message/comment inside input function
e.g. :
x = input("Enter First Number")
or
print("Enter first number ")
x =input()
Another important point is input() function all ways take input in string form (data type) i.e.
" str " data type
so if I run a program on pyCharm
a=input("enter first number") b=input("enter second number") z = a + b print(z) Assume I enter first number as 5 and second as 4 output come as a 54 instead of 9 this is because it treat input as a string data type to overcome this problem we have to tell compiler that it is a integer to do that we need two more variable and convert it into integer data type a=input("enter first number") x=int(a) b=input("enter second number") y=int(b) z = x+y print(z) output = 9 or we can do it directly a=int(input("enter first number")) b=int(input("enter second number")) z= a +b print(z) output = 9 Char input in Python : As we have discuss in our article "data types in Python" about character data type ,Python don't have a char data type but python provides string and we have to convert it into a char data type ,To get a single char from string we have to mention its index number e.g. : ch = input("enter a char") print =(ch[0]) or ch = input("enter a char ") [0] print(ch) and in this way we can take a char input from user *We can evaluate the expression that user will enter by using a function eval(). eval() function will evaluate the expression enter by user and it will pass the answer e.g.: ev = eval(input("Enter the expression")) print(ev)This function is vary important while building a programme for calculator Compiler will stop execution of code when it comes to input() function and start when user enter the input I hope this article on input from user is helpful for u Thank u 😊