Math Expression Hacks Collaborators_ipynb_2_
π‘ Hack 1: Identify Sequencing, Selection, and Iteration
Instructions
Analyze the following algorithm. Identify which steps demonstrate sequencing, selection, and iteration.
- Sequencing: Steps that happen one after another in order.
- Selection: A decision is made that can lead to different outcomes.
- Iteration: A step or set of steps repeats based on a condition.
Algorithm
- Set item to the number to search for
- Get next number in the list
- If number = item, display βitem foundβ
- If there are more numbers in the list, go back to Step 2
- Display βitem not foundβ
type your answers here:
Sequencing:
Selection:
Iteration:
π‘ Hack 2: Predict the Output
Instructions
Analyze the following code segment. Predict what is displayed when it runs.
- Track how each variable changes after every line.
- Apply arithmetic operations carefully and in order.
- Remember that assignment updates the variable immediately.
Code Segment
- num1 β 2
- num2 β 4
- num3 β 5
- num1 β num2 + num3
- num3 β num1 + 5
- num2 β (num1 + num3) / 5
- DISPLAY(num1)
- DISPLAY(num2)
- DISPLAY(num3)
```python
Replace the ? with your answers
# Step-by-step tracking
num1 = 2
num2 = 4
num3 = 5
# after num1 β num2 + num3
num1 = ?
# after num3 β num1 + 5
num3 = ?
# after num2 β (num1 + num3)/5
num2 = ?
# Predicted Output
DISPLAY(num1) β ?
DISPLAY(num2) β ?
DISPLAY(num3) β ?
π‘ Hack 3: Practice
Instructions: Predict the value of result
after executing the following code. Show your thought process and write your answer below. You can type and test this in VS Code.dev if you want.
num1 β 40
num2 β num1 / 2
num3 β 5 * num2 + 3
result β num2 MOD 3 * num1 + 4 - num3 / 2
DISPLAY(result)
```python
Write Your Answer Here
result = ______