Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

[AP CSP] Programming with Conditionals [If, Elif, Else]

Total questions: 35

Worksheet time: 2hrs 59mins

Name
Class
Date
1.
The second part of if, that is executed when the condition is false
a)
if
b)
else
c)
for
d)
input
2.
Which statement will check to see if a is equal to b?
a)
if a == b
b)
if a = b:
c)
if a != b:
d)
if a == b:
3.
What will be printed to the screen?
a)
Nothing
b)
Success
c)
Failure
d)
Success
 Failure
4.
What will be printed to the screen?
a)
Success
b)
Failure
c)
Part of the way there!
d)
Nothing
5.

What will be printed to the screen?

a)

Failure

b)

Part of the way there!

c)

Success

d)

Nothing

6.
Which statement will check to see if a is both less than b and less than c?
a)
if a < b < c:
b)
if a < b and a < c:
c)
if a < b and c:
d)
if a < b and b < c
7.
Which of the following are comparators
a)
Equal to (==)
b)
Not equal to (!=)
c)
Less than or equal to (<=)
d)
All of the above
8.
 == 
a)
compares whether two things are equal
b)
assigns a value to a variable
9.
 = 
a)
compares whether two things are equal
b)
assigns a value to a variable
10.
What will the following lines of code print?
a)
A
b)
B C
c)
A B C
d)
Nothing, it will return an error.
11.
What is my result?
john = 5                                                                        .
if john > 6:                                                                  .
.            print("John is getting ice cream")
else:                                                                               .
.               print("John is getting apple juice")
print("John is getting grapes")                    .
a)
John is getting ice cream
John is getting grapes
b)
John is getting apple juice
John is getting grapes
c)
John is getting apple juice
d)
John is getting ice cream
12.
What is the result of running this code?
a)
You're living a good life!
b)
You're living a fantastic life!
c)
You're too young!
d)
The code runs with errors
13.
What is the result of running this code?
a)
You're living a good life!
b)
You're too young!
c)
Runs with errors
d)
None of the above
14.
There is an error in the code below. What line is the error in?
a)
Line 1
b)
Line 3
c)
Line 5
d)
Line 7
15.
Let’s say that I wanted to write a program that asked a user their age. Then I wanted to use a conditional construct to see if the age that they input was between 13 and 18. What would the conditional statement be?
a)
if age >= 13 and age >= 18:
b)
if age >= 13 and age =< 18:
c)
if age =< 13 and age =< 18:
d)
if age =< 13 and age >= 18:
16.

Which of the following scenarios is best suited for using chained else-if statements?

a)

Printing "YES" or "NO" in a program

b)

Sorting an LIST of Integers.

c)

Determining the grade based on a score.

d)

Calculating the factorial of a number.

17.

You are building a weather application. Which feature would require the use of chained else-if statements?

a)

Recommending an outfit based on the weather conditions.

b)

Displaying the current temperature.

c)

Showing the name of the city.

d)

Displaying the time of sunset.

18.

You are creating a simple video game. In which scenario would chained else-if statements be useful?

a)

Managing player statuses (e.g., "Healthy", "Injured", "Poisoned").

b)

Drawing game characters.

c)

Updating the game clock.

d)

Loading game assets.

19.

When would you NOT use chained else-if statements?

a)

When there are multiple, mutually exclusive conditions

b)

When only one condition can be true at a time

c)

When you need to run the same block of code for all conditions

d)

When you are checking ranges of numbers

20.

Which of the following is a disadvantage of using too many chained else-if statements?

a)

They can be hard to read and maintain.

b)

They execute all the conditions.

c)

They only work for numerical values.

d)

They cannot be nested.

21.

This is a catch-all for every other situation besides the one where the condition is true.

a)

then

b)

do

c)

else

d)

if

22.

If you want to test more than one condition (chained condition), what do you use after if statement?

a)

elif

b)

else

c)

ifif

d)

else if

23.

Data type that can only be true or false

a)

int

b)

string

c)

boolean

d)

float

24.

Which character must be at the end of the line for if?

a)

:

b)

;

c)

.

d)

{

25.

Which symbol means "not equal to"?

a)

==

b)

<=

c)

>=

d)

!=

26.

What is the output?

a)

250.0

b)

200.0

c)

300.0

d)

350.0

27.

What will display at the end of the program running?

a)

You can ride the carousel!

b)

Nothing will display

c)

Sorry! Not tall enough!

d)

There will be an error.

28.

What is the output?

a)

next

stop

b)

next

c)

stop

d)

syntax error - program doesn't work

29.

What is the output?

a)

3

b)

3

7

c)

3

5

7

d)

7

30.

What is the output?

a)

True

b)

NIL

c)

True

NIL

d)

True

NIL

NIL

31.

What is the output?

a)

level 3

b)

level 3

level 1

c)

level 3

level 1

NIL

d)

level 3

level 2

level 1

NIL

32.

Given the nested if-else below, what will be the value x when the code is executed successfully.

a)

0

b)

4

c)

2

d)

3

33.

Given the nested if-else structure below, what will be the value of x after code execution completes.

a)

2

b)

0

c)

3

d)

4

34.
This operator means that one value is the same as the other value
a)
==
b)
!=
c)
>
d)
<
35.

What is a conditional?

a)

if clause

b)

asks a yes or no question

c)

decides whether to skip a section of code

d)

code that might be skipped