Guess the output
What is wrong with this code
WILL IT RUN?
CS LOGIC
CS WILD CARD
100

x = 4

x += 3

print(x)

7

100

What is wrong with this code?

if x > 5

    print("Big!")

Missing a colon : after x > 5.

100

How will the following code run:

A — Runs normally
B — Syntax Error
C — Runtime Error
D — Infinite Loop

print(2 ** 3)

Answer: A — Runs normally

100

Binary only uses 0 and 1.

What is:

1010

in regular decimal numbers?

10

100

You try to visit a website and get:

404

What does that usually mean?

Answer: Page Not Found

200

print("CS" * 3)

CSCSCS

200

Find the bug:

score = 10


if score = 10:

    print("Perfect!")

Answer: It should be ==, not =.


200

How will the following code run:

A — Runs normally
B — Syntax Error
C — Runtime Error
D — Infinite Loop

print("5" + 5)

Answer: C — Runtime Error

Python can't add a string and an integer.

200

What does this Boolean expression evaluate to?

True AND (False OR True)


True

200

You accidentally delete half your code.

What keyboard shortcut might save your life?

Answer: Ctrl + Z ( undo)

300

nums = [1, 2, 3]

nums[1] = nums[0] + nums[2]

print(nums)

answer: [1,4,3]

300

Why does this crash?

age = 16

print("Age: " + age)

Answer: You can't concatenate a string and an integer.

300

How will the following code run:

A — Runs normally
B — Syntax Error
C — Runtime Error
D — Infinite Loop

for i in range(3)

    print(i)

Answer: B — Syntax Error (missing :)


300

Imagine a stack:

You perform:

PUSH A

PUSH B

PUSH C

POP

What is now on top of the stack

B

(c was the most recent item, so POP removes it)

300

Which one is NOT technically a programming language?

A. Python
B. Java
C. HTML
D. C++

Answer: C. HTML

HTML is a markup language.

400

word = "PYTHON"

print(word[::-2])

NHY

400

Find the bug:

nums = [10, 20, 30]

for i in range(len(nums) + 1):

    print(nums[i])

Answer: + 1 makes the loop try to access nums[3], which doesn't exist.

fix: range(len(nums))

400

How will the following code run:

A — Runs normally
B — Syntax Error
C — Runtime Error
D — Infinite Loop

x = 1


while x < 5:

    x -= 1


print(x)

Answer: D — Infinite Loop

400

How many times does this loop run?

x = 1

while x <= 20:

    x *= 2

5 times

400

Question:

Python was NOT named after the snake.

What was it named after?

A. A scientist
B. Monty Python
C. A video game
D. A computer company

Answer: B. Monty Python(a famous british comedy group)

500

x = 5


for i in range(3):

    x = x - i


print(i, x)

2 2

500

This programmer expects [2, 4, 6], but gets [1, 2, 3].

Why?

def double(nums):

    for n in nums:

        n = n * 2

    return nums

print(double([1, 2, 3]))

Answer: Changing n does not change the actual values inside the list.

500

How will the following code run:

A — Runs normally
B — Syntax Error
C — Runtime Error
D — Infinite Loop

x = 0

while x < 3:

    x += 1

    if x == 2:

        x = 0

print(x)

Answer: D — Infinite Loop

500

A computer is trying to find the shortest path from A to D.

The connections have these costs:

A → B = 2

A → C = 6

B → C = 1

B → D = 5

C → D = 2

What is the cheapest path?

Answer: A → B → C → D

cost: 2+1+2 =5

500

A programmer gets stuck, puts a rubber duck next to their computer, and explains their entire code to the duck line by line.

What debugging technique is this?

Answer: Rubber Duck Debugging

Explaining your code out loud can help you notice your own mistake.