Types,%20Truth,%20and%20Expressions

About This Presentation
Title:

Types,%20Truth,%20and%20Expressions

Description:

Title: Welcome to CS I Author: System Administrator Last modified by: Sarah Created Date: 8/11/2003 5:41:56 PM Document presentation format: On-screen Show (4:3) –

Number of Views:121
Avg rating:3.0/5.0
Slides: 17
Provided by: SystemA386
Learn more at: http://www.cs.uni.edu
Category:

less

Transcript and Presenter's Notes

Title: Types,%20Truth,%20and%20Expressions


1
Types, Truth, and Expressions
  • Intro to Computer Science
  • CS1510, Section 2
  • Dr. Sarah Diesburg

2
What type(s) would we use
  • To represent your
  • Weight
  • Height
  • Age
  • Name
  • Class status (freshman, sophomore, etc)
  • Gender
  • If you owe the university money
  • If you are taking classes this semester

3
Yesterdays Lab Main Concept Review
  • First we looked at the idea of Conditionals and
    the basic six operators
  • Less than lt
  • Greater than gt
  • Equal to (Not the same as )
  • Not equal to !
  • Less than or equal to lt
  • Greater than or equal to gt

4
Yesterdays Lab Main Concept Review
  • The results of a conditional operator is always a
    Boolean value.
  • Meaning ???
  • Either True or False

5
Boolean Expressions
  • George Booles (mid-1800s) mathematics of
    logical expressions
  • Boolean expressions (conditions) have a
    value of True or False
  • Conditions are the basis of choices in a
    computer, and, hence, are the basis of the
    appearance of intelligence in them.

6
What is True, and What is False
  • True any nonzero number or nonempty object. 1,
    100, hello, a,b
  • False zero number or empty object. 0, ,
  • Special values called True and False, which
    are just stand-ins for 1 and 0. However, they
    print nicely (True or False)

7
Boolean Expression
  • Every boolean expression has the form
  • expression booleanOperator expression
  • The result of evaluating something like the above
    is just True or False.
  • Evaluating a boolean operation is a binary
    operation
  • if (altb) has two operands in expression
  • However, remember what constitutes True or False
    in Python!
  • If (a) will evaluate to True if a is non-zero!

8
Relational Operators
  • Relational Operators have low preference
  • 5 3 lt 3 2
  • (5 3) lt (3 - 2)
  • 8 lt 1
  • False

9
Selection
  • Then we looked at how conditionals are applied in
    selection statements.
  • Selection is how programs make choices, and it is
    the process of making choices that provides a lot
    of the power of computing

10
(No Transcript)
11
(No Transcript)
12
Python if Statement
  • if boolean_expression
  • suite
  • evaluate the boolean_expression (True or False)
  • if True, execute all statements in the suite

13
Warning About Indentation
  • Elements of the suite must all be indented the
    same number of spaces/tabs
  • Python only recognizes suites when they are
    indented the same distance
  • You must be careful to get the indentation right
    to get suites right.

14
Python Selection, Round 2
  • if boolean expression
  • suite1
  • else
  • suite2
  • The process is
  • evaluate the boolean
  • if True, run suite1
  • if False, run suite2

15
Chained Comparisons
  • In python, chained comparisons work just like you
    would expect in a mathematical expression
  • Given myInt has the value 5
  • 0 lt myInt lt 5
  • True
  • 0 lt myInt lt 5 gt 10
  • False

16
Compound Expressions
  • Logically 0 lt X lt 3 is actually(0 lt X) and (X lt
    3)
  • Logical Operators (lower case)
  • and
  • or
  • not
Write a Comment
User Comments (0)
About PowerShow.com