1 / 12

Computer Science 101

Computer Science 101. If Statement. Python Relational Operators. Primitive Conditions. Conditions are expressions which evaluate to true or false . One kind of condition is the comparison of two numerical values of the same type. Examples: Payrate > 10 (x+10) == (y*z -8).

tamika
Download Presentation

Computer Science 101

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science 101 If Statement

  2. Python Relational Operators

  3. Primitive Conditions • Conditions are expressions which evaluate to true or false. • One kind of condition is the comparison of two numerical values of the same type. • Examples: Payrate > 10 (x+10) == (y*z -8)

  4. Conditional Operation: If-Statement • Syntaxif <condition> : <list of statements> • <condition> would be replaced by actual condition, etc. • The colon is required • The list of statements, must be indented – part of the syntax for Python

  5. T Cond F The If-Statement • Semantics: • the condition is evaluated • if the condition is true, the list of statements is executed

  6. If-Statement examples • if yearsWorked > 10 : bonus = 1000 • if age >= 65 : total = 0.85 * total numSeniors = numSeniors + 1

  7. The If-else-Statement • Syntaxif <condition> : <list of statements> else : <list of statements> • Note colon after else • Both lists must be indented.

  8. F T Cond Conditional Operation: if-then-else • Semantics: • the condition is evaluated • if the condition is true, the list of statements is executed

  9. If-Else-Statement examples • if yearsWorked > 10 : bonus = 1000 else : bonus = 500 • if age >= 65 : price = 0.85 * pricenumSeniors = numSeniors + 1 else :nonSeniors = nonSeniors + 1

  10. Python Session

  11. Python Session (cont)

  12. While I'm resting, you boys ...

More Related