Use of comments in Python
User input (text based) in Python
Mastery 28 – User input (text based) in Python (basic) input(“prompt”) is one of the many Built-in Functions of the Python interpreter. The prompt is written as an output, the function recieves an input from the user and converts it to a data type, usually a string. For this data to have a meaning in the program, it should be saved inside a […]
Mastery 28 – User input (text based) in Python (basic) input(“prompt”) is one of the many Built-in Functions of the Python interpreter. The prompt is written as an output, the function recieves an input from the user and converts it to a data type, usually a string. For this data to have a meaning in the program, it should be saved inside a […]
But variables are not just text, they can also be numbers. These numbers can be float numbers or integers. Float numbers are the ones that have decimal values, and integers are the ones without decimal values.
User input (text based) in Python (basic)
User input (text based) in Python (basic)
One of the basic things every one who learns programming do is to say Hello to hte world, and to make the user say hello to the world; in python 3 terms, it would be the print command, and the input command. So really really … Continúa leyendo Input and output, the basics: Masteries 10, 28
One of the basic things every one who learns programming do is to say Hello to hte world, and to make the user say hello to the world; in python 3 terms, it would be the print command, and the… Continue Reading →
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: