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:
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.