ISA 281
Exam 1 Review
Free Python Resources
This material is outside the course and will not be tested upon.
While it's not part of the course, Python for Data Analysis is a great resource for improving your programming skills(plus it’s Free !). It covers some essential Python libraries(Numpy, Pandas and Matplotlib) and I highly recommend reading it. Continuous learning is always better than sprint learning.
Agenda
How things will work
Slides
Practice Notebook
Slides and practice notebook cover the same topics in order. Make a copy of the exam1_review.ipynb from canvas.
Make a copy of this document
Make a copy of this document
Files > Save a copy in Drive
Collab Link available in Canvas under Exam Review
Some things before we begin
Pseudocode
Example
IF HoursWorked > NormalMax THEN
Display overtime message
ELSE
Display regular time message
ENDIF
Source: Cal Poly
Variables
print()
The print() function in Python is used to output text to the console. It has several parameters that you can use to control its behavior:
```python
print(*objects, sep='', end='\n', file=None, flush=False)
```
Operators
Arithmetic
Relational
Logical
Assignment
1+1
x=1
x>2
True and True
Python Arithmetic Operators
a + b | Sum a and b (7) |
a - b | Subtract b from a (-1) |
a * b | a times b (12) |
a / b | a divided by b (0.75) |
a // b | Integer part of a divided by b (0) |
a % b | Rest of a divided by b (3) |
a ** b | a to the power of b (81) |
Cheat Sheet
25 / 6 =4.167
return round-down(4.167)
Floor Division
Mod (Remainder)
27 / 5 = 5*5 + 2
Practice Question Exam Style - Augmented Assignment 1
Python Assignment Operators
Operator | Example | Same As |
= | x = 5 | x = 5 |
+= | x += 3 | x = x + 3 |
-= | x -= 3 | x = x - 3 |
Same as
Same as
Same as
Example
Augmented Operators
Python Relational Operators
> and >= | Greater than and greater than equal to |
< and <= | Less than and Less than equal to |
== | Equal to |
!= | Not Equal to |
Example
“=” always comes in the end of a relational operator
Python Logical Operators
Operator | Description | Example |
and | Returns True if both statements are true | x < 5 and x < 10 |
or | Returns True if one of the statements is true | x < 5 or x < 4 |
not | Reverse the result, returns False if the result is true | not(x < 5 and x < 10) |
Practice Question Exam Style - Logical 1
If statements
Conditions are either True/False
Nested if Statements
if x == y:
print('x and y are equal')
else:
if x < y:
print('x is less than y')
else:
print('x is greater than y')
Outer
Inner
Nested loops can be hard to read when they get too long. Is there any way we can use just 1 level of if statements and get the job done. Hint - Logical Operators and elif
This can be asked as a direct question on the exam
For Loop
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
Example
For in some Iterable Object
Do this for item in object
For Loop - break and range()
Break
range(start, stop, step=1)
While Loop
Coding Exercise: Hard while Loop problem
Feedback