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
‘#Mastery15’ Articles at TC101 Fall 2015, Page 4
Introduction to Programming Python and C++

Tag Archives: #Mastery15

#Mastery15 and #Mastery16

Use of the conditional “if” Use of “else” with a conditional

If, Elif, and Else

     A condition is an operation used in programs to see if something is true or not. These conditionals help you doing ac action whenever they are true. During this post I will guide you on how to use them properly for the creation of a program:


     First of all we need to understand which ones are these conditionals.


      The first one is called IF. We place it in the middle of out code to see if a condition is true or false. We can only place it once, the rest of the conditions will be evaluated by a different function.


     The second one is ELIF. This one can be used to evaluate many conditions along the same IF. This function can be used as many times as you want, as long as you state the word “elif” followed by the statement you want to evalute.


      ELSE is the last conditional. It is use to stablish what will happen in case none of the conditions above is true.

      Now, we are creating a program that will evaluate a given number and show if it´s positive, negative or 0.


     So we start by asking the user for a number. 


    How we start with our first condition; if the number is greater than zero, then it´s a positive number. So, for this we need to type if followed by the condition that would be x>0. At the end of the line we place a colon ( : ).


     After this, we need the program to let the user know that the number is positive, se we create an output. This output need to be intended to show that is the action the computer should do in case the condition is true.


       If this condition is not true, then it means that the number is zero or a negative number. To differentiate if this number is zero or negative we will need another conditional. But as we explained before, this conditional cannot be an IF conditional, but an ELIF.


      An ELIF conditional works just an IF conditional: you place the word “elif” followed by the condition “x==0” and ending with a colon. Now the condition we will be evaluating is if the number is equal to zero. (It is necessary to place two equal signs to evaluate)


     If none of this conditions are true, then we know that the number given by the user if not zero or greater than zero; therefore, this number is lower than zero. We know that the only numbers that are lower than zero are negative numbers.


     Based on the previous reasoning, if this numbers fails to be true in both conditionals, then it is a negative number.


     Now we know we don´t need to evaluate in any other condition so we can use the conditional ELSE. For this, we only write the word “else” followed by a colon. That, we just need to type the action we want the computer to do.

      And this is what will happen when you run this program:


If, Elif, and Else


#MASTERY15,16,17

Use of conditionals in python 3.

#MASTERY15,16,17

Use of conditionals in python 3.

#Mastery16 – Use of “else” with a conditional

Hello! Here is my that is about using else in conditionals. An else statement is used on conditional to set the false part. If a value that is introduced does not fulfill the true condition, there is when the else takes part in the process. This is used to have a response to a false condition.

 

For example:

 

If you want to create a simple program for grading, that describes when a student is approved or has failed the semester, this program would have to make the sum of the three partials and calculate the average. Let´s say the approbatory grade is 70. To start, you can begin it in many ways. I would choose to do it with an if condition.

 

The goal here is for the program to print the phrase approved or failed depending on the sum of the partial grades. This program, of course, to proof the use of the else statement.

 

To begin, we would have to type what we regularly do in all of the coding processes.

 

using namespace std;

 

Then, we would have to begin with the input of each one of the partials. For the program to get the average of the three and then with an if condition, tell if the student is approved or has failed.

 

The code would be:

 

Remember that to use an else statement you have to make use of the conditional with the true condition. Al else has to follow a conditional to work. When you write an else, the response has to be following the else in between braces, this helps the condition to realize what to execute when the false condition is applied. For example:

 

If(average>=7){

cout

}

else {

cout

}

 

Remember to always make use of the correct punctuation, spaces and symbols for the code. The semicolon is very important to be included at the end of each line (That is my most common mistake).

 

 

 

Here is the running program. As you can see, I used the else statement to print the string when the student failed.

Tip: if your program does not work when you are trying to compile do not freak out, the compiler will try to tell you what he doesn’t understand. Here is an example of an error, the numbers show the line and the number of character in which the error is placed.

 

 

The compiler says there is a semicolon missing in line 5 space 31…

 

 

 

 

Remember to check to learn how to use if conditionals.

 

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

WATCH MY VIDEO https://youtu.be/951plPJV2VE

MASTERY 15 AND 17

  The IF statement is used for conditional execution. What you do in IF is that you write a condition (a specific case) so when the program encounter that conditional it will do the command or function you gave to him (in my example if Z is bigger than X, in that case the program will […]

Masteries 15, 16, and 17: Use a condicional “if” with “else” and “elif”

“If” is really simple. You write a parameter with variables such that if thats true, the program does something. The “else” makes it so that of the parameters of the conditional aren’t met, the program does something else. And an “elif” is like an “else” but with a conditional. Here’s an example.

Masteries 15 and 16!

Here is my SECOND video about the masteries. 

Hope it helps.

It’s about:

  1. Use of the conditional “if”
  2. Use of “else” with a conditional

#Mastery15 – Use of the conditional “if”

Hey! This is about using the conditional “if”. First things first we need to know what is it for. The conditional If is used when you want to give the program command a condition. This means that when you enter some kind of information to the program, it gives back a response depending on it´s condition.

 

Conditionals have their own symbology, here are the basics you need to know in order to begin with conditional coding.

 

> Greater than

>= Bigger than or equal to

! = Unequal to

== Equals to

 

What is the structure of an If statement?

 

To program something using the conditional “If” you have to begin with…

if (true statement) execute the next.

The true statement refers to a condition you choose to be done if what is introduced fulfills the condition. The true statement has to be always in between parenthesis. If what is introduced is true, the program proceeds to execute what is given to the statement. For example:

x = 1

If(x>o) {

cout

 

If you ran the program with this conditional, the resulting action would be displaying the string given, because 1 fulfills the condition 1>0.

 

If the condition is not true, then we would prefer to use the else option. What does else do? Else does the action of the false response. If what is introduced to the program doesn’t fulfill the true condition, then the else would be executed. For example:

x = -1

If(x>o) {

cout

 

else {

cout

 

If you ran this program with this conditional, the resulting action would be displaying the string given in the else command. This because -1 does not fulfill the true condition so the else command is executed.

 

For example, imagine you are doing a program for an ice-cream store. This store has two ranges of flavor which differ in price. If you are getting a flavor from group number one, the price of each cone is $20.00, but if you are getting a cone with flavor from group number two, the price of each cone is $30.0.

 

You would, first, need an action for the cashier to input in which group of  flavor the ice cream is, and then use a conditional to display which type of price is it depending on the type of ice-cream. Here is the example code:

 

 

WATCH MY VIDEO https://youtu.be/Q6ysIRGGoaQ

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

 

Use of the conditional “if”

La forma más simple del condicional if: Lo que se encuentra entre () después de if es la condición, si esta se cumple aparecerá la frase que se pone a continuación con COUT. Agregar iostream, namespace, int main. Dar un… Continue Reading →

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