Hello!! Here i´m going to show you how to write and print a text based user input.

Print text based user input

Lets say that you want to ask for the name of the user and then print it. It´s something very simple that requires an imput. Here I will show you my code:

In the code I created a variable called Name that is going to take the value of whatever the user           input is, inside the INPUT function I asked the user for his/her name. It´s important to keep the           user informed about what you want him to give you, always fill the parenthesis with the inormation     you want to ask him because f youi leave it in blank the user will not know what to write.

This is the code working:

As you noticed, the string that I wrote inside the INPUT function (between the parenthesis) is what Python asked me to write. Then I wrote my name and the variable Name took that string value. When the program printed Name it printed what I wrote.

In the PRINT function we are telling the program that we want to print the variable Name, this is not between the quotes because it´s a variable, remember that if you want to print a string you have to use the quotes. Also, you can combine variables and strings in the same PRINT function, let me show you:

 If i write “José Carlos” as my name and “17” as my age what this program should do is to print ” Your name is José Caros Peñuelas and your are 17 years old”. Lets see if this works:

 Well, something obviously went wrong. Lets see what it was.

 Oh I see now, the variables (shown in black by default) should be separated from the text with commas “,”, this is the way that python recognize that you want a variable there  and not a string.
This is the correct way to do it, notice that i have the commas now:

The program will put the value of name and age between the strings. Notice that in the PRINT function I separated the variables from the strings with a comma. This is the code working:

Integer input

Now let´s try the same thing but with numbers:

This program is goint to tell the user to write a number, then is going to take that value and put it into num2 where is going to be added to 35. At the end is going to print 35 plus whatever the user wrote.
Lets see how it works:
AN ERROR?!?! Why? The print shuld be 40 because 5 + 35 = 40
This happened because the input value is always a string. Python ignores what the user wrote, it just take it as a string no matter if it´s a number or a word. But, what happens if i want to work with numbers? You have to tell python that you want that input to be an integer. To do that write the INT function and inside put eh input, like this:
Now python knows that the input is going to be an integer and now it can be used as a number. This is how the program should work: 
Now that you now how to use an input is important that you tell python what type of value you are expecting. If is a string the leave it that way, but if is an integer or a float be sure to write the type function and inside put the input. One very common mistake is that people forget to write a double parenthesis at the end of the input (like it´s shown on the picture above), be sure to close the INT function and the INPUT function always.

CC BY 4.0 Materies 10 and 28 – Print and User input by Jose Carlos Peñuelas Armenta is licensed under a Creative Commons Attribution 4.0 International License.