#8 - Input function
Input function
Till now we have learned many things and now we are going towards taking inputs from the user. This is as easy as the print function.
So how to do it?
All we have to do is to use Input() function. Wherever this function is in the code, the execution stops and waits for the user to enter some text in it as an input. If we want to pass any string as a hint for the user, we give it as an argument to the function which means we put it in the parenthesis. We also need to store the input data into a variable for further processing and so an input function always has a variable declaration in the starting. Always remember that the given input is by default in a string type and you need to convert it into any desired data type to perform anything on the data.
Let's have a look at an example code:-
First, we took the input from the user and saves it in a variable named name. Then we gave an output using that variable.
By default, the input given is in string type but we can convert it to another type using the following functions.
int() - integer
bool() - boolean
float() - decimal
code:-
Awesome
ReplyDelete