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

Tag Archives: #Mastery16

#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

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

Use of “else” with a conditional

Esta es otra forma de utilizar condicional. Condicional alternativa. En esta se presentan dos posibilidades y la condición determina cual se ejecuta, así como también qué aparecer o hacer con los valores restantes que no aparecen en la condición. Agregar… Continue Reading →

#Mastery15 #Mastery16 and #Mastery17 in one video !

Hey today we are going to learn how to use conditions in Pythons 3 : Use of the conditional “if” Use of “else” with a conditional Use of “elif” with a conditional #Mastery15/16/17 : Have a good day !

Masteries 15 and 16 – If and Else

Here I will show you that I know how to use IF and ELSE stamentes.This is the basic form, I put it simple to understand the syntax quickly. Here are some works that I made using IF and ELSEs.If you want to know more check my WSQs.

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