Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152
‘#mastery28’ Articles at TC101 Fall 2015, Page 2
Introduction to Programming Python and C++

Tag Archives: #mastery28

Masteries 7 & 28

Use of comments in Python
User input (text based) in Python

Masteries 26 & 28

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 […]

Masteries 26 & 28

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 […]

User Input

     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:

User Input


#MASTERY28

User input (text based) in Python (basic)

#MASTERY28

User input (text based) in Python (basic)

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 input command. So really really … Continúa leyendo Input and output, the basics: Masteries 10, 28

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 →

Materies 10 and 28 – Print and User input

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.

Materies 10 and 28 - Print and User input

 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.

What should you work on?

Week #12 and more partial exams for you.

For this week's readings:
C++ (TC1017) should either be looking at support for your project, ImageMagick C++ libraries are a good start.
Python (TC1014) should be finishing chapter 11 (Dictionaries).