W4_Lecture 4A (1).pptx - Advanced Programming Conditional execution Project analysis slide 2 Nested conditionals Chained conditionals Alternative

W4_Lecture 4A (1).pptx - Advanced Programming Conditional...

• Notes
• 37

This preview shows page 1 - 12 out of 37 pages.

Subscribe to view the full document.

Project analysis slide 2 Conditional execution Lecture- 4A Boolean expressions Logical operators Conditional execution Nested conditionals Chained conditionals Alternative execution
Project analysis slide 2 Boolean expressions A Boolean expression is an expression that is either true or false . Examples using the operator “==“ ~ Compares two operands ~ Produces True if they are equal and False otherwise

Subscribe to view the full document.

Project analysis slide 2 Boolean expressions True and False are special values that belong to the class bool . They are not strings.
Project analysis slide 2 Boolean expressions The == operator is one of the comparison operators. T he others are:

Subscribe to view the full document.

Project analysis slide 2 Boolean expressions Python symbols are different from the mathematical symbols for the same operations . A common error is to use a single equal sign (=) instead of a double equal sign (==). = is an assignment operator . == is a comparison operator . There is no such thing as =< or =>.
Project analysis slide 2 Logical operators There are three logical operators: and, or, as well as not. The semantics (meaning) of these operators is similar to their meaning in English. Example: x > 0 and x < 10 ~is true only if x is greater than 0 and less than 10. n%2 == 0 or n%3 == 0 ~is true if either of the conditions (number is divisible by 2 or 3) is true.

Subscribe to view the full document.

Project analysis slide 2 Logical operators The not operator negates a Boolean expression , ~not (x > y) is true if x > y is false; that is, if x is less than or equal to y. Python is not very strict. Any nonzero number is interpreted as “true.”
Project analysis slide 2 Conditional execution Ability is needed to check conditions and behaviour of the program. Conditional statements give this ability. ~The simplest form is the if statement: The Boolean expression, after the if-statement , is called the condition . End the if-statement with a colon character (:) The line(s) after the if statement are indented.

Subscribe to view the full document.

Project analysis slide 2 Conditional execution The if logic diagram is given below:
Project analysis slide 2 Conditional execution If the logical condition is true , then the indented statement gets executed .

Subscribe to view the full document.

• Fall '12
• Sung

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes