πŸ’‘ 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

  1. Set item to the number to search for
  2. Get next number in the list
  3. If number = item, display β€œitem found”
  4. If there are more numbers in the list, go back to Step 2
  5. 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 = ______