What is the purpose of a variable in a program?
Describe a situation where you would use an if-else-if statement.
Answers will vary.
Why do we use functions in code?
To organize code, reduce repetition, and make the code easier to read and manage.
Which of the following is a logical operator?
&&
Identify the bug
y = 10
print(Y)
Y should by y
Define a variable named age and set it equal to 16
What does != mean in conditionals?
Not equal to
What does it mean to “call” a function?
Use the function in your program
Explain the difference between and and or operators.
And requires all conditions to be met.
Or only requires one condition to be met.
What will this code print?
x = 10
if x < 5:
print("Less than 5")
else:
print("5 or more")
5 or more
What is the value of x after this code runs
x = 5
x = x + 3
8
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"
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.
What do the following conditions check?
if age >= 18 and has_id
Checks if age is 18 or older and has_id is True.
Identify the bug.
print(Hello, world!)
We need quotations around "Hello, world!"
Which of the following variable names is not valid?
1st_number
number_1
num_1
1st_number
What will the following code print?
score = 80
if score >= 90:
print("A")
elif score >= 80:
print("B")
else:
print("C")
B
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!
Write a condition that checks if x is greater than 10 or y is less than 5.
x > 10 || y < 5
Identify the bug:
def say_hello():
print("Hello, World!")
sayHello()
sayHello() should be say_hello()
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
Write an if-else statement to print "Pass" if grade is 60 or higher, otherwise print "Fail".
console.log "Pass"
else console.log "Fail"
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)
Evaluate this expression.
x < 10 || x >= 3
TRUE
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.