Sometimes, as a programmer, we need to consider that every user needs a program for them. However, this is not possible, but it is possible to use the same program for different users. For example we would like a program to greet everyone by their name, but not everyone’s name is the same. For this, we use variables.

      Variables  called this way because they can keep changing along with a program. Reviewing the example before; we would like this program to greet everyone by their name. If the value that keeps changing is the name, then the name has to become a variable. To convert the name into a variable we type it like this:

Name=

     However, we cannot just type a random name after the equal sign. If we do this, the program will always greet a person in particular. For changing this, we need to state the variable as an input:

Name=input(“What´s your name?”)

     When running this, the user will see the following text on their screen:

What´s your name?


     After this, the user is allowed to type their respective name and the program will register it as the value of name. Therefore, when we print the variable, the user can see the text they typed:

       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.

       For example, a float number will be 3.2837 and its integer will be 3.

       For turning the input into a number we need to type “float” if we want it to be a float number or “int” if we wat it to be an integer between the equal sign and the “input”.

      For example, this program asks for the value of 2 numbers that will be float numbers and shows you the sum of those.

        The same code can be used for integer numbers. You just need to change “float” for “int” and the result will be different:


CC BY 4.0 User Input by Frida Diaz is licensed under a Creative Commons Attribution 4.0 International License.