Variables
Conditionals
Functions
Logical and Comparison Operators
Code Tracing and Debugging
100

What is the purpose of a variable in a program?

To store a value
100

Describe a situation where you would use an if-else-if statement.

Answers will vary.

100

Why do we use functions in code?

To organize code, reduce repetition, and make the code easier to read and manage.

100

Which of the following is a logical operator?

  • a) +
  • b) -
  • c) &&
  • d) %

&&

100

Identify the bug

y = 10

print(Y)


Y should by y

200

Define a variable named age and set it equal to 16

var age = 16
200

What does != mean in conditionals?

Not equal to

200

What does it mean to “call” a function?

Use the function in your program

200

Explain the difference between and and or operators.

And requires all conditions to be met.

Or only requires one condition to be met.

200

What will this code print?

x = 10

if x < 5:

    print("Less than 5")

else:

    print("5 or more")


5 or more

300

What is the value of x after this code runs

x = 5

x = x + 3


8

300

What is the output of this code if x=10?

if x > 5:

    print("Greater than 5")

else:

    print("Less than 5")


"Greater than 5"

300

What does it mean to define a function?

It is the code where the function is created and named, including the actions the function will perform when called.

300

What do the following conditions check?

if age >= 18 and has_id


Checks if age is 18 or older and has_id is True.

300

Identify the bug.

print(Hello, world!)


We need quotations around "Hello, world!"

400

Which of the following variable names is not valid?

1st_number

number_1

num_1

1st_number

400

What will the following code print?

score = 80

if score >= 90:

    print("A")

elif score >= 80:

    print("B")

else:

    print("C")


B

400

What will be printed if you define a function greet() that prints "Hello!" and then call it three times in a row?

Hello!

Hello!

Hello!

400

Write a condition that checks if x is greater than 10 or y is less than 5.

x > 10 || y < 5

   

400

Identify the bug:

def say_hello():

    print("Hello, World!")

sayHello()


sayHello() should be say_hello()

500

Explain the difference between a global variable and a local variable.

Global Variable: Defined outside of a function or on event, applies to the entire code

Local Variable: Defined inside a function or on event, applies specifically to the function or on event it is inside

500

Write an if-else statement to print "Pass" if grade is 60 or higher, otherwise print "Fail".

if grade >= 60

 console.log "Pass"

else console.log "Fail"

500

Define a function calculate_area that takes width and height and tells us the area of a rectangle.

var area

function calculate_area

area = width * height

console.log(area)

500

Evaluate this expression.

x < 10 || x >= 3

TRUE

500

Identify the bug.

age = 18

if age > 18:

    print("Older than 18")

elif age = 18:

    print("Exactly 18")

else:

    print("Younger than 18")


age = 18 should say age == 18.

M
e
n
u