Download presentation
Presentation is loading. Please wait.
1
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
2
Issues from PA01 Turn in your paperwork, stapled, in order given on assignment Include a header block Which includes your full name Proper format for variableNames From now on can use CONSTANT_NAMES for constants File names matter – give it the name that was requested No line wrap
3
Issues from PA01 Make sure you READ directions
The directions told you what order the data should be given Days, hours, minutes, seconds Test your code! I specifically gave you an example for each program. It better work on this. But, this wasn’t enough examples to guarantee everything worked. What other things should you test?
4
Observations from PA 1 Variable names matter (don’t call it minuteStr when it contains a number) Why would you import math? Why would you say float(2.2) Do your own work!
5
Questions about PA02??
6
Line Wrap Reminder Some rules
Strings must be closed in the line in which they start Adding a backslash at the end of the line tells python that the command is continued on the end of the line
7
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
8
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.
9
Let’s test your knowledge
Let‘s look at #1-4 in my questions.py program…
10
Let’s test your knowledge
Problems #1-4 : Which letters are printed? A B A and B Neither
11
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
12
Python Selection, Round 2
if boolean expression: suite1 else: suite2 The process is: evaluate the boolean if True, run suite1 if False, run suite2
13
Python Selection, Round 3
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
14
Python Selection, Round 3
if boolean expression1: suite1 elif boolean expression2: suite2 #(as many elif’s as you want) else: suiteLast
15
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
16
Compound Expressions Logical Operators (lower case) and or not
17
Let’s test your knowledge
Problems #10-11 : Which letters are printed? A B A and B Neither
18
Truth Tables
19
Truth Tables
20
Truth Tables
21
Truth Tables
22
Truth Tables
23
Chained Comparisons You are going to be tempted to write:
0 <= myInt <= 5 But you will need to be very careful
24
Compound Evaluation Logically 0 < X < 3 is actually (0 < X) and (X < 3) Evaluate using X with a value of 2: (0< X) and (X< 3) Parenthesis first: (True) and (True) Final value: True (Note: parentheses are not necessary in this case.)
25
Compound Evaluation BUT, I’ve seen students write: 3 < X < 0
Meaning they want to know if x is outside of that range. But this is actually (3 < X) and (X < 0) Evaluate using X with a value of 5: (3< X) and (X< 0) Parenthesis first: (True) and (False) Final value: False
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.