Python lesson: Getting user input through the console. Bonus: handling an exception.
This is my second article about the Python programming language. And what we are going to learn today is handling user input from the console.
Python makes getting user input from the console very easy. For this purpose we can use the input function, which has this structure:
1
input([prompt])
This function only takes the prompt as an argument, which would be the text that the user would see before the console goes into input mode.
To store input from a user into a variable you can simply assign the return value of the function to a variable like this:
1
userInput = input('Give me a value');
With that little information we can make a little program that will get a number from the user and print it’s square.