



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is introductory course for computer science. Its about basic concepts involving in computer programming, structure and working. Key points in this lecture handout are: Conditionals, Boolean Expressions, Logical Expressions, Basic Conditional Execution, Conditional Statement Syntax, Boolean Condition, Flow Charts
Typology: Study notes
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Today ...
Logical expressions can be nested
((not (2 > 3)) or (4 < 2)) and not ((2 > 3) or False) True
If operands are not Boolean expressions, Python will convert for us
17 and 54 54
0 or 20 20
len([10, 20]) or "spam" 2
len([10, 20]) and "spam" "spam"
What is going on?
Conditional statement syntax if boolean condition: statement statement ...
Flow Charts
if x < y: # condition x = x + 1 # if statement y = y - 1 # statement after if
Condi&on
Statement
Statement
False True x^ <^ y^?
x = x + 1
y = y - 1
No Yes
If-Else statement syntax if boolean condition: statements else: statements
The flow chart
if x < y: x = x + 1 else x = x - 1 y = y - 1
Condi&on
Statement
Statement
False True x^ <^ y^?
x = x + 1
y = y - 1
No Yes
Statement x = x - 1
Simple example using elif conditional statement ...
def min3(x, y, z): if x <= y and x <= z: return x elif y <= x and y <= z: return y else: return z