Download presentation
Presentation is loading. Please wait.
1
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
2
Observations from PA 1 Variable names matter (don’t call it startingMileageStr when it contains a number) Import math? Why would you say float(2.2) Do your own work!
3
Review : Python if Statement
if <expression> : suite Evaluate the expression to a Boolean value (True or False) if True, execute all statements in the suite
4
Review : 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.
5
Let’s test your knowledge
Look at #1-4 in my questions.py program… Which letters are printed? A B A and B Neither
6
Python Selection The process is: evaluate the boolean
if boolean expression: suite1 else: suite2 The process is: evaluate the boolean if True, run suite1 if False, run suite2
7
Let’s test your knowledge
Let’s look at statements with if, elif, else Problems #5-9 : Which letters are printed? A B A and B Neither
8
Python Selection The process is: evaluate expression1
if boolean expression1: suite1 elif expression2: suite2 The process is: evaluate expression1 if True, run suite1 If False, evaluate expression 2 if True, run suite2
9
Python Selection – All Together
if boolean expression1: suite1 elif boolean expression2: suite2 #(as many elif’s as you want) else: suiteLast
10
if, elif, else, the Process
Evaluate boolean expressions until: The boolean expression returns True None of the boolean expressions return True If a boolean returns True, run the corresponding suite. Skip the rest of the if If no boolean returns True, run the else suite, the default suite
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.