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

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

Advanced Programming Python
Image of page 1

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
Image of page 2
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
Image of page 3

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.
Image of page 4
Project analysis slide 2 Boolean expressions The == operator is one of the comparison operators. T he others are:
Image of page 5

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 =>.
Image of page 6
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.
Image of page 7

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.”
Image of page 8
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.
Image of page 9

Subscribe to view the full document.

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

Subscribe to view the full document.

Image of page 12
  • Fall '12
  • Sung

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    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